Java Code Examples for com.example.android.common.logger.Log#e()

The following examples show how to use com.example.android.common.logger.Log#e() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PermissionRequestFragment.java    From android-PermissionRequest with Apache License 2.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    // This is for runtime permission on Marshmallow and above; It is not directly related to
    // PermissionRequest API.
    if (requestCode == REQUEST_CAMERA_PERMISSION) {
        if (permissions.length != 1 || grantResults.length != 1 ||
                grantResults[0] != PackageManager.PERMISSION_GRANTED) {
            Log.e(TAG, "Camera permission not granted.");
        } else if (mWebView != null && mWebServer != null) {
            mWebView.loadUrl("http://localhost:" + mWebServer.getPort() + "/sample.html");
        }
    } else {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
 
Example 2
Source File: ImageFetcher.java    From android-DisplayingBitmaps with Apache License 2.0 6 votes vote down vote up
@Override
protected void clearCacheInternal() {
    super.clearCacheInternal();
    synchronized (mHttpDiskCacheLock) {
        if (mHttpDiskCache != null && !mHttpDiskCache.isClosed()) {
            try {
                mHttpDiskCache.delete();
                if (BuildConfig.DEBUG) {
                    Log.d(TAG, "HTTP cache cleared");
                }
            } catch (IOException e) {
                Log.e(TAG, "clearCacheInternal - " + e);
            }
            mHttpDiskCache = null;
            mHttpDiskCacheStarting = true;
            initHttpDiskCache();
        }
    }
}
 
Example 3
Source File: ImageFetcher.java    From graphics-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void closeCacheInternal() {
    super.closeCacheInternal();
    synchronized (mHttpDiskCacheLock) {
        if (mHttpDiskCache != null) {
            try {
                if (!mHttpDiskCache.isClosed()) {
                    mHttpDiskCache.close();
                    mHttpDiskCache = null;
                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "HTTP cache closed");
                    }
                }
            } catch (IOException e) {
                Log.e(TAG, "closeCacheInternal - " + e);
            }
        }
    }
}
 
Example 4
Source File: ImageFetcher.java    From graphics-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void clearCacheInternal() {
    super.clearCacheInternal();
    synchronized (mHttpDiskCacheLock) {
        if (mHttpDiskCache != null && !mHttpDiskCache.isClosed()) {
            try {
                mHttpDiskCache.delete();
                if (BuildConfig.DEBUG) {
                    Log.d(TAG, "HTTP cache cleared");
                }
            } catch (IOException e) {
                Log.e(TAG, "clearCacheInternal - " + e);
            }
            mHttpDiskCache = null;
            mHttpDiskCacheStarting = true;
            initHttpDiskCache();
        }
    }
}
 
Example 5
Source File: ImageCache.java    From android-DisplayingBitmaps with Apache License 2.0 6 votes vote down vote up
/**
 * Clears both the memory and disk cache associated with this ImageCache object. Note that
 * this includes disk access so this should not be executed on the main/UI thread.
 */
public void clearCache() {
    if (mMemoryCache != null) {
        mMemoryCache.evictAll();
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "Memory cache cleared");
        }
    }

    synchronized (mDiskCacheLock) {
        mDiskCacheStarting = true;
        if (mDiskLruCache != null && !mDiskLruCache.isClosed()) {
            try {
                mDiskLruCache.delete();
                if (BuildConfig.DEBUG) {
                    Log.d(TAG, "Disk cache cleared");
                }
            } catch (IOException e) {
                Log.e(TAG, "clearCache - " + e);
            }
            mDiskLruCache = null;
            initDiskCache();
        }
    }
}
 
Example 6
Source File: BluetoothChatService.java    From android-BluetoothChat with Apache License 2.0 6 votes vote down vote up
public void run() {
    Log.i(TAG, "BEGIN mConnectedThread");
    byte[] buffer = new byte[1024];
    int bytes;

    // Keep listening to the InputStream while connected
    while (mState == STATE_CONNECTED) {
        try {
            // Read from the InputStream
            bytes = mmInStream.read(buffer);

            // Send the obtained bytes to the UI Activity
            mHandler.obtainMessage(Constants.MESSAGE_READ, bytes, -1, buffer)
                    .sendToTarget();
        } catch (IOException e) {
            Log.e(TAG, "disconnected", e);
            connectionLost();
            break;
        }
    }
}
 
Example 7
Source File: BluetoothChatService.java    From connectivity-samples with Apache License 2.0 6 votes vote down vote up
public AcceptThread(boolean secure) {
    BluetoothServerSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    // Create a new listening server socket
    try {
        if (secure) {
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,
                    MY_UUID_SECURE);
        } else {
            tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(
                    NAME_INSECURE, MY_UUID_INSECURE);
        }
    } catch (IOException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
    }
    mmServerSocket = tmp;
    mState = STATE_LISTEN;
}
 
Example 8
Source File: ImageFetcher.java    From android-DisplayingBitmaps with Apache License 2.0 6 votes vote down vote up
@Override
protected void closeCacheInternal() {
    super.closeCacheInternal();
    synchronized (mHttpDiskCacheLock) {
        if (mHttpDiskCache != null) {
            try {
                if (!mHttpDiskCache.isClosed()) {
                    mHttpDiskCache.close();
                    mHttpDiskCache = null;
                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "HTTP cache closed");
                    }
                }
            } catch (IOException e) {
                Log.e(TAG, "closeCacheInternal - " + e);
            }
        }
    }
}
 
Example 9
Source File: LoyaltyCardReader.java    From android-CardReader with Apache License 2.0 6 votes vote down vote up
/**
 * Callback when a new tag is discovered by the system.
 *
 * <p>Communication with the card should take place here.
 *
 * @param tag Discovered tag
 */
@Override
public void onTagDiscovered(Tag tag) {
    Log.i(TAG, "New tag discovered");
    // Android's Host-based Card Emulation (HCE) feature implements the ISO-DEP (ISO 14443-4)
    // protocol.
    //
    // In order to communicate with a device using HCE, the discovered tag should be processed
    // using the IsoDep class.
    IsoDep isoDep = IsoDep.get(tag);
    if (isoDep != null) {
        try {
            // Connect to the remote NFC device
            isoDep.connect();
            // Build SELECT AID command for our loyalty card service.
            // This command tells the remote device which service we wish to communicate with.
            Log.i(TAG, "Requesting remote AID: " + SAMPLE_LOYALTY_CARD_AID);
            byte[] command = BuildSelectApdu(SAMPLE_LOYALTY_CARD_AID);
            // Send command to remote device
            Log.i(TAG, "Sending: " + ByteArrayToHexString(command));
            byte[] result = isoDep.transceive(command);
            // If AID is successfully selected, 0x9000 is returned as the status word (last 2
            // bytes of the result) by convention. Everything before the status word is
            // optional payload, which is used here to hold the account number.
            int resultLength = result.length;
            byte[] statusWord = {result[resultLength-2], result[resultLength-1]};
            byte[] payload = Arrays.copyOf(result, resultLength-2);
            if (Arrays.equals(SELECT_OK_SW, statusWord)) {
                // The remote NFC device will immediately respond with its stored account number
                String accountNumber = new String(payload, "UTF-8");
                Log.i(TAG, "Received: " + accountNumber);
                // Inform CardReaderFragment of received account number
                mAccountCallback.get().onAccountReceived(accountNumber);
            }
        } catch (IOException e) {
            Log.e(TAG, "Error communicating with card: " + e.toString());
        }
    }
}
 
Example 10
Source File: BluetoothChatService.java    From connectivity-samples with Apache License 2.0 6 votes vote down vote up
public void run() {
    Log.i(TAG, "BEGIN mConnectedThread");
    byte[] buffer = new byte[1024];
    int bytes;

    // Keep listening to the InputStream while connected
    while (mState == STATE_CONNECTED) {
        try {
            // Read from the InputStream
            bytes = mmInStream.read(buffer);

            // Send the obtained bytes to the UI Activity
            mHandler.obtainMessage(Constants.MESSAGE_READ, bytes, -1, buffer)
                    .sendToTarget();
        } catch (IOException e) {
            Log.e(TAG, "disconnected", e);
            connectionLost();
            break;
        }
    }
}
 
Example 11
Source File: BluetoothChatService.java    From connectivity-samples with Apache License 2.0 6 votes vote down vote up
public ConnectedThread(BluetoothSocket socket, String socketType) {
    Log.d(TAG, "create ConnectedThread: " + socketType);
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) {
        Log.e(TAG, "temp sockets not created", e);
    }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
    mState = STATE_CONNECTED;
}
 
Example 12
Source File: BluetoothChatService.java    From connectivity-samples with Apache License 2.0 6 votes vote down vote up
public ConnectThread(BluetoothDevice device, boolean secure) {
    mmDevice = device;
    BluetoothSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    // Get a BluetoothSocket for a connection with the
    // given BluetoothDevice
    try {
        if (secure) {
            tmp = device.createRfcommSocketToServiceRecord(
                    MY_UUID_SECURE);
        } else {
            tmp = device.createInsecureRfcommSocketToServiceRecord(
                    MY_UUID_INSECURE);
        }
    } catch (IOException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
    }
    mmSocket = tmp;
    mState = STATE_CONNECTING;
}
 
Example 13
Source File: BluetoothChatService.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
public void cancel() {
    try {
        mmSocket.close();
    } catch (IOException e) {
        Log.e(TAG, "close() of connect socket failed", e);
    }
}
 
Example 14
Source File: BluetoothChatService.java    From android-BluetoothChat with Apache License 2.0 5 votes vote down vote up
public void run() {
    Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType);
    setName("ConnectThread" + mSocketType);

    // Always cancel discovery because it will slow down a connection
    mAdapter.cancelDiscovery();

    // Make a connection to the BluetoothSocket
    try {
        // This is a blocking call and will only return on a
        // successful connection or an exception
        mmSocket.connect();
    } catch (IOException e) {
        // Close the socket
        try {
            mmSocket.close();
        } catch (IOException e2) {
            Log.e(TAG, "unable to close() " + mSocketType +
                    " socket during connection failure", e2);
        }
        connectionFailed();
        return;
    }

    // Reset the ConnectThread because we're done
    synchronized (BluetoothChatService.this) {
        mConnectThread = null;
    }

    // Start the connected thread
    connected(mmSocket, mmDevice, mSocketType);
}
 
Example 15
Source File: MainActivity.java    From android-play-places with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to format information about a place nicely.
 */
private static Spanned formatPlaceDetails(Resources res, CharSequence name, String id,
        CharSequence address, CharSequence phoneNumber, Uri websiteUri) {
    Log.e(TAG, res.getString(R.string.place_details, name, id, address, phoneNumber,
            websiteUri));
    return Html.fromHtml(res.getString(R.string.place_details, name, id, address, phoneNumber,
            websiteUri));

}
 
Example 16
Source File: MainActivity.java    From android-play-places with Apache License 2.0 5 votes vote down vote up
@Override
public void onComplete(Task<PlaceBufferResponse> task) {
    try {
        PlaceBufferResponse places = task.getResult();

        // Get the Place object from the buffer.
        final Place place = places.get(0);

        // Format details of the place for display and show it in a TextView.
        mPlaceDetailsText.setText(formatPlaceDetails(getResources(), place.getName(),
                place.getId(), place.getAddress(), place.getPhoneNumber(),
                place.getWebsiteUri()));

        // Display the third party attributions if set.
        final CharSequence thirdPartyAttribution = places.getAttributions();
        if (thirdPartyAttribution == null) {
            mPlaceDetailsAttribution.setVisibility(View.GONE);
        } else {
            mPlaceDetailsAttribution.setVisibility(View.VISIBLE);
            mPlaceDetailsAttribution.setText(
                    Html.fromHtml(thirdPartyAttribution.toString()));
        }

        Log.i(TAG, "Place details received: " + place.getName());

        places.release();
    } catch (RuntimeRemoteException e) {
        // Request did not complete successfully
        Log.e(TAG, "Place query did not complete.", e);
        return;
    }
}
 
Example 17
Source File: ProvisioningValuesLoader.java    From android-NfcProvisioning with Apache License 2.0 5 votes vote down vote up
private void loadFromDisk(HashMap<String, String> values) {
    File directory = Environment.getExternalStorageDirectory();
    File file = new File(directory, FILENAME);
    if (!file.exists()) {
        return;
    }
    Log.d(TAG, "Loading the config file...");
    try {
        loadFromFile(values, file);
    } catch (IOException e) {
        e.printStackTrace();
        Log.e(TAG, "Error loading data from " + file, e);
    }
}
 
Example 18
Source File: ImageCache.java    From android-DisplayingBitmaps with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the disk cache.  Note that this includes disk access so this should not be
 * executed on the main/UI thread. By default an ImageCache does not initialize the disk
 * cache when it is created, instead you should call initDiskCache() to initialize it on a
 * background thread.
 */
public void initDiskCache() {
    // Set up disk cache
    synchronized (mDiskCacheLock) {
        if (mDiskLruCache == null || mDiskLruCache.isClosed()) {
            File diskCacheDir = mCacheParams.diskCacheDir;
            if (mCacheParams.diskCacheEnabled && diskCacheDir != null) {
                if (!diskCacheDir.exists()) {
                    diskCacheDir.mkdirs();
                }
                if (getUsableSpace(diskCacheDir) > mCacheParams.diskCacheSize) {
                    try {
                        mDiskLruCache = DiskLruCache.open(
                                diskCacheDir, 1, 1, mCacheParams.diskCacheSize);
                        if (BuildConfig.DEBUG) {
                            Log.d(TAG, "Disk cache initialized");
                        }
                    } catch (final IOException e) {
                        mCacheParams.diskCacheDir = null;
                        Log.e(TAG, "initDiskCache - " + e);
                    }
                }
            }
        }
        mDiskCacheStarting = false;
        mDiskCacheLock.notifyAll();
    }
}
 
Example 19
Source File: BluetoothChatService.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
public void cancel() {
    Log.d(TAG, "Socket Type" + mSocketType + "cancel " + this);
    try {
        mmServerSocket.close();
    } catch (IOException e) {
        Log.e(TAG, "Socket Type" + mSocketType + "close() of server failed", e);
    }
}
 
Example 20
Source File: CardStreamLinearLayout.java    From android-BatchStepSensor with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void initialize(AttributeSet attrs, int defStyle) {

    float speedFactor = 1.f;

    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs,
                R.styleable.CardStream, defStyle, 0);

        if( a != null ){
            int speedType = a.getInt(R.styleable.CardStream_animationDuration, 1001);
            switch (speedType){
                case ANIMATION_SPEED_FAST:
                    speedFactor = 0.5f;
                    break;
                case ANIMATION_SPEED_NORMAL:
                    speedFactor = 1.f;
                    break;
                case ANIMATION_SPEED_SLOW:
                    speedFactor = 2.f;
                    break;
            }

            String animatorName = a.getString(R.styleable.CardStream_animators);

            try {
                if( animatorName != null )
                    mAnimators = (CardStreamAnimator) getClass().getClassLoader()
                            .loadClass(animatorName).newInstance();
            } catch (Exception e) {
                Log.e(TAG, "Fail to load animator:" + animatorName, e);
            } finally {
                if(mAnimators == null)
                    mAnimators = new DefaultCardStreamAnimator();
            }
            a.recycle();
        }
    }

    mAnimators.setSpeedFactor(speedFactor);
    mSwipeSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
    setOnHierarchyChangeListener(mOnHierarchyChangeListener);
}