Example usage for android.widget ImageView getDrawable

List of usage examples for android.widget ImageView getDrawable

Introduction

In this page you can find the example usage for android.widget ImageView getDrawable.

Prototype

public Drawable getDrawable() 

Source Link

Document

Gets the current Drawable, or null if no Drawable has been assigned.

Usage

From source file:es.upv.riromu.arbre.main.MainActivity.java

/******************************************/
public void cropImage(View view) {
    Intent intent = new Intent(this, CropImageActivity.class);
    ImageView imv = (ImageView) findViewById(R.id.image_intro);
    try {/*w  w  w  .j a v  a2  s  . co m*/
        image = ((BitmapDrawable) imv.getDrawable()).getBitmap();
        croppedimage_uri = Uri.fromFile(createImageFile());

    } catch (IOException e) {
        e.printStackTrace();
    }

    //Convert to byte array
    if (getImageUri() != null) {
        intent.putExtra("image", getImageUri().toString());//tostring for passing it
        intent.putExtra("imageSave", croppedimage_uri.toString());//tostring for passing it
        intent.putExtra(RETURN_DATA, true);
        //     intent.putExtra(RETURN_DATA_AS_BITMAP, true);
    } else {
        intent.putExtra("image", "default");
    }
    intent.putExtra(CropImageActivity.SCALE, true);
    intent.putExtra(CropImageActivity.ASPECT_X, 3);
    intent.putExtra(CropImageActivity.ASPECT_Y, 2);
    try {

        startActivityForResult(intent, CROP_IMAGE);
    } catch (Exception e) {
        Log.e(TAG, "Error calling crop" + e.getMessage());
    }
}

From source file:com.master.metehan.filtereagle.AdapterLog.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    long time = cursor.getLong(colTime);
    int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
    int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
    String flags = cursor.getString(colFlags);
    String saddr = cursor.getString(colSAddr);
    int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort));
    String daddr = cursor.getString(colDAddr);
    int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
    String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName));
    int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
    String data = cursor.getString(colData);
    int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed));
    int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection));
    int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive));

    // Get views/* w  w  w  . j a va 2s.  co m*/
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol);
    TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
    TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr);
    TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort);
    final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr);
    TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort);
    final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization);
    ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
    TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
    TextView tvData = (TextView) view.findViewById(R.id.tvData);
    ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection);
    ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive);

    // Show time
    tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));

    // Show connection type
    if (connection <= 0)
        ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked);
    else {
        if (allowed > 0)
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on);
        else
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable());
        DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff);
    }

    // Show if screen on
    if (interactive <= 0)
        ivInteractive.setImageDrawable(null);
    else {
        ivInteractive.setImageResource(R.drawable.screen_on);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable());
            DrawableCompat.setTint(wrap, colorOn);
        }
    }

    // Show protocol name
    tvProtocol.setText(Util.getProtocolName(protocol, version, false));

    // SHow TCP flags
    tvFlags.setText(flags);
    tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE);

    // Show source and destination port
    if (protocol == 6 || protocol == 17) {
        tvSPort.setText(sport < 0 ? "" : getKnownPort(sport));
        tvDPort.setText(dport < 0 ? "" : getKnownPort(dport));
    } else {
        tvSPort.setText(sport < 0 ? "" : Integer.toString(sport));
        tvDPort.setText(dport < 0 ? "" : Integer.toString(dport));
    }

    // Application icon
    ApplicationInfo info = null;
    PackageManager pm = context.getPackageManager();
    String[] pkg = pm.getPackagesForUid(uid);
    if (pkg != null && pkg.length > 0)
        try {
            info = pm.getApplicationInfo(pkg[0], 0);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    if (info == null)
        ivIcon.setImageDrawable(null);
    else if (info.icon == 0)
        Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
    else {
        Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon);
        Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon);
    }

    // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
    uid = uid % 100000; // strip off user ID
    if (uid == -1)
        tvUid.setText("");
    else if (uid == 0)
        tvUid.setText(context.getString(R.string.title_root));
    else if (uid == 9999)
        tvUid.setText("-"); // nobody
    else
        tvUid.setText(Integer.toString(uid));

    // Show source address
    tvSAddr.setText(getKnownAddress(saddr));

    // Show destination address
    if (resolve && !isKnownAddress(daddr))
        if (dname == null) {
            if (tvDaddr.getTag() == null) {
                tvDaddr.setText(daddr);
                new AsyncTask<String, Object, String>() {
                    @Override
                    protected void onPreExecute() {
                        tvDaddr.setTag(id);
                    }

                    @Override
                    protected String doInBackground(String... args) {
                        try {
                            return InetAddress.getByName(args[0]).getHostName();
                        } catch (UnknownHostException ignored) {
                            return args[0];
                        }
                    }

                    @Override
                    protected void onPostExecute(String name) {
                        Object tag = tvDaddr.getTag();
                        if (tag != null && (Long) tag == id)
                            tvDaddr.setText(">" + name);
                        tvDaddr.setTag(null);
                    }
                }.execute(daddr);
            }
        } else
            tvDaddr.setText(dname);
    else
        tvDaddr.setText(getKnownAddress(daddr));

    // Show organization
    tvOrganization.setVisibility(View.GONE);
    if (organization) {
        if (!isKnownAddress(daddr) && tvOrganization.getTag() == null)
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    tvOrganization.setTag(id);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return Util.getOrganization(args[0]);
                    } catch (Throwable ex) {
                        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        return null;
                    }
                }

                @Override
                protected void onPostExecute(String organization) {
                    Object tag = tvOrganization.getTag();
                    if (organization != null && tag != null && (Long) tag == id) {
                        tvOrganization.setText(organization);
                        tvOrganization.setVisibility(View.VISIBLE);
                    }
                    tvOrganization.setTag(null);
                }
            }.execute(daddr);
    }

    // Show extra data
    if (TextUtils.isEmpty(data)) {
        tvData.setText("");
        tvData.setVisibility(View.GONE);
    } else {
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
}

From source file:com.zhengde163.netguard.AdapterLog.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    long time = cursor.getLong(colTime);
    int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
    int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
    String flags = cursor.getString(colFlags);
    String saddr = cursor.getString(colSAddr);
    int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort));
    String daddr = cursor.getString(colDAddr);
    int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
    String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName));
    int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
    String data = cursor.getString(colData);
    int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed));
    int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection));
    int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive));

    // Get views//from w  ww  .  j a  va 2s  .com
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol);
    //        TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
    TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr);
    TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort);
    final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr);
    TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort);
    final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization);
    ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
    TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
    TextView tvData = (TextView) view.findViewById(R.id.tvData);
    ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection);
    ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive);

    // Show time
    tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));

    // Show connection type
    if (connection <= 0)
        ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked);
    else {
        if (allowed > 0)
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on);
        else
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable());
        DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff);
    }

    // Show if screen on
    if (interactive <= 0)
        ivInteractive.setImageDrawable(null);
    else {
        ivInteractive.setImageResource(R.drawable.screen_on);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable());
            DrawableCompat.setTint(wrap, colorOn);
        }
    }

    // Show protocol name
    tvProtocol.setText(Util.getProtocolName(protocol, version, false) + flags);

    // SHow TCP flags
    //        tvFlags.setText(flags);
    //        tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE);

    // Show source and destination port
    if (protocol == 6 || protocol == 17) {
        tvSPort.setText(sport < 0 ? "" : getKnownPort(sport));
        tvDPort.setText(dport < 0 ? "" : getKnownPort(dport));
    } else {
        tvSPort.setText(sport < 0 ? "" : Integer.toString(sport));
        tvDPort.setText(dport < 0 ? "" : Integer.toString(dport));
    }

    // Application icon
    ApplicationInfo info = null;
    PackageManager pm = context.getPackageManager();
    String[] pkg = pm.getPackagesForUid(uid);
    if (pkg != null && pkg.length > 0)
        try {
            info = pm.getApplicationInfo(pkg[0], 0);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    if (info == null)
        ivIcon.setImageDrawable(null);
    else if (info.icon == 0)
        Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
    else {
        Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon);
        Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon);
    }

    // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
    uid = uid % 100000; // strip off user ID
    if (uid == -1)
        tvUid.setText("");
    else if (uid == 0)
        tvUid.setText(context.getString(R.string.title_root));
    else if (uid == 9999)
        tvUid.setText("-"); // nobody
    else
        tvUid.setText(Integer.toString(uid));

    // Show source address
    tvSAddr.setText(getKnownAddress(saddr));

    // Show destination address
    if (resolve && !isKnownAddress(daddr))
        if (dname == null) {
            if (tvDaddr.getTag() == null) {
                tvDaddr.setText(daddr);
                new AsyncTask<String, Object, String>() {
                    @Override
                    protected void onPreExecute() {
                        tvDaddr.setTag(id);
                    }

                    @Override
                    protected String doInBackground(String... args) {
                        try {
                            return InetAddress.getByName(args[0]).getHostName();
                        } catch (UnknownHostException ignored) {
                            return args[0];
                        }
                    }

                    @Override
                    protected void onPostExecute(String name) {
                        Object tag = tvDaddr.getTag();
                        if (tag != null && (Long) tag == id)
                            tvDaddr.setText(">" + name);
                        tvDaddr.setTag(null);
                    }
                }.execute(daddr);
            }
        } else
            tvDaddr.setText(dname);
    else
        tvDaddr.setText(getKnownAddress(daddr));

    // Show organization
    tvOrganization.setVisibility(View.GONE);
    if (organization) {
        if (!isKnownAddress(daddr) && tvOrganization.getTag() == null)
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    tvOrganization.setTag(id);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return Util.getOrganization(args[0]);
                    } catch (Throwable ex) {
                        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        return null;
                    }
                }

                @Override
                protected void onPostExecute(String organization) {
                    Object tag = tvOrganization.getTag();
                    if (organization != null && tag != null && (Long) tag == id) {
                        tvOrganization.setText(organization);
                        tvOrganization.setVisibility(View.VISIBLE);
                    }
                    tvOrganization.setTag(null);
                }
            }.execute(daddr);
    }

    // Show extra data
    if (TextUtils.isEmpty(data)) {
        tvData.setText("");
        tvData.setVisibility(View.GONE);
    } else {
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
}

From source file:de.grobox.liberario.DirectionsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // remember view for UI changes when fragment is not active
    mView = inflater.inflate(R.layout.fragment_directions, container, false);
    locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    checkPreferences();/*from  w ww  .ja va 2s .c om*/

    setFromUI();
    setToUI();

    // timeView
    final Button timeView = (Button) mView.findViewById(R.id.timeView);
    timeView.setText(DateUtils.getcurrentTime(getActivity()));
    timeView.setTag(Calendar.getInstance());
    timeView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showTimePickerDialog();
        }
    });

    // set current time on long click
    timeView.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            timeView.setText(DateUtils.getcurrentTime(getActivity()));
            timeView.setTag(Calendar.getInstance());
            return true;
        }
    });

    Button plus10Button = (Button) mView.findViewById(R.id.plus15Button);
    plus10Button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            addToTime(15);
        }
    });

    // dateView
    final Button dateView = (Button) mView.findViewById(R.id.dateView);
    dateView.setText(DateUtils.getcurrentDate(getActivity()));
    dateView.setTag(Calendar.getInstance());
    dateView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showDatePickerDialog();
        }
    });

    // set current date on long click
    dateView.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            dateView.setText(DateUtils.getcurrentDate(getActivity()));
            dateView.setTag(Calendar.getInstance());
            return true;
        }
    });

    // Trip Date Type Spinner (departure or arrival)
    final TextView dateType = (TextView) mView.findViewById(R.id.dateType);
    dateType.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (dateType.getText().equals(getString(R.string.trip_dep))) {
                dateType.setText(getString(R.string.trip_arr));
            } else {
                dateType.setText(getString(R.string.trip_dep));
            }
        }
    });

    // Products
    final ViewGroup productsLayout = (ViewGroup) mView.findViewById(R.id.productsLayout);
    for (int i = 0; i < productsLayout.getChildCount(); ++i) {
        final ImageView productView = (ImageView) productsLayout.getChildAt(i);
        final Product product = Product.fromCode(productView.getTag().toString().charAt(0));

        // make inactive products gray
        if (mProducts.contains(product)) {
            productView.getDrawable().setColorFilter(null);
        } else {
            productView.getDrawable().setColorFilter(getResources().getColor(R.color.highlight),
                    PorterDuff.Mode.SRC_ATOP);
        }

        // handle click on product icon
        productView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (mProducts.contains(product)) {
                    productView.getDrawable().setColorFilter(getResources().getColor(R.color.highlight),
                            PorterDuff.Mode.SRC_ATOP);
                    mProducts.remove(product);
                    Toast.makeText(v.getContext(), LiberarioUtils.productToString(v.getContext(), product),
                            Toast.LENGTH_SHORT).show();
                } else {
                    productView.getDrawable().setColorFilter(null);
                    mProducts.add(product);
                    Toast.makeText(v.getContext(), LiberarioUtils.productToString(v.getContext(), product),
                            Toast.LENGTH_SHORT).show();
                }
            }
        });

        // handle long click on product icon by showing product name
        productView.setOnLongClickListener(new OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                Toast.makeText(view.getContext(), LiberarioUtils.productToString(view.getContext(), product),
                        Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }

    if (!Preferences.getPref(getActivity(), Preferences.SHOW_ADV_DIRECTIONS)) {
        (mView.findViewById(R.id.productsScrollView)).setVisibility(View.GONE);
    }

    Button searchButton = (Button) mView.findViewById(R.id.searchButton);
    searchButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NetworkProvider np = NetworkProviderFactory.provider(Preferences.getNetworkId(getActivity()));
            if (!np.hasCapabilities(NetworkProvider.Capability.TRIPS)) {
                Toast.makeText(v.getContext(), v.getContext().getString(R.string.error_no_trips_capability),
                        Toast.LENGTH_SHORT).show();
                return;
            }

            AsyncQueryTripsTask query_trips = new AsyncQueryTripsTask(v.getContext());

            // check and set to location
            if (checkLocation(FavLocation.LOC_TYPE.TO)) {
                query_trips.setTo(getLocation(FavLocation.LOC_TYPE.TO));
            } else {
                Toast.makeText(getActivity(), getResources().getString(R.string.error_invalid_to),
                        Toast.LENGTH_SHORT).show();
                return;
            }

            // check and set from location
            if (mGpsPressed) {
                if (getLocation(FavLocation.LOC_TYPE.FROM) != null) {
                    query_trips.setFrom(getLocation(FavLocation.LOC_TYPE.FROM));
                } else {
                    mAfterGpsTask = query_trips;

                    pd = new ProgressDialog(getActivity());
                    pd.setMessage(getResources().getString(R.string.stations_searching_position));
                    pd.setCancelable(false);
                    pd.setIndeterminate(true);
                    pd.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    mAfterGpsTask = null;
                                    dialog.dismiss();
                                }
                            });
                    pd.show();
                }
            } else {
                if (checkLocation(FavLocation.LOC_TYPE.FROM)) {
                    query_trips.setFrom(getLocation(FavLocation.LOC_TYPE.FROM));
                } else {
                    Toast.makeText(getActivity(), getString(R.string.error_invalid_from), Toast.LENGTH_SHORT)
                            .show();
                    return;
                }
            }

            // remember trip if not from GPS
            if (!mGpsPressed) {
                FavDB.updateFavTrip(getActivity(), new FavTrip(getLocation(FavLocation.LOC_TYPE.FROM),
                        getLocation(FavLocation.LOC_TYPE.TO)));
            }

            // set date
            query_trips.setDate(DateUtils.mergeDateTime(getActivity(), dateView.getText(), timeView.getText()));

            // set departure to true of first item is selected in spinner
            query_trips.setDeparture(dateType.getText().equals(getString(R.string.trip_dep)));

            // set products
            query_trips.setProducts(mProducts);

            // don't execute if we still have to wait for GPS position
            if (mAfterGpsTask != null)
                return;

            query_trips.execute();
        }
    });

    return mView;
}

From source file:es.upv.riromu.arbre.main.MainActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    FileOutputStream fos;// w w w  . j a  v a2s . co  m

    if (image != null) {
        try {
            String fileName = "temp_image.jpg";
            String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                    .getPath() + "/" + fileName;

            fos = new FileOutputStream(fileURL);
            image.compress(Bitmap.CompressFormat.JPEG, compressRatio, fos);
            outState.putBoolean("image", true);
            image.recycle();
            System.gc();
        } catch (Exception e) {
            Log.e(TAG, "Error " + e.getMessage());
        }
    }
    if (state[CROP_IMAGE]) {
        try {
            String fileName = "temp_cropped.jpg";
            String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                    .getPath() + "/" + fileName;

            fos = new FileOutputStream(fileURL);
            croppedimage.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            outState.putBoolean("croppedimage", true);
            fos.close();
            croppedimage.recycle();
            System.gc();

        } catch (Exception e) {
            Log.e(TAG, "Error " + e.getMessage());
        }
    }
    if (state[TREAT_IMAGE]) {
        try {
            String fileName = "temp_treated.jpg";
            String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                    .getPath() + "/" + fileName;
            fos = new FileOutputStream(fileURL);

            ImageView imv = (ImageView) findViewById(R.id.image_intro);
            ((BitmapDrawable) imv.getDrawable()).getBitmap().compress(Bitmap.CompressFormat.JPEG, 100, fos);
            outState.putBoolean("treatedimage", true);
            fos.close();

        } catch (Exception e) {
            Log.e(TAG, "Error " + e.getMessage());
        }
    }

    if (image_uri != null) {
        outState.putString("image_uri", image_uri.getPath());
    }
    outState.putIntArray("colours", colours);
    outState.putBoolean("cropping", state[CROP_IMAGE]);
    outState.putBoolean("treated", state[TREAT_IMAGE]);

    super.onSaveInstanceState(outState);
}

From source file:de.grobox.liberario.DirectionsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_navigation_expand:
        View productsScrollView = mView.findViewById(R.id.productsScrollView);
        if (productsScrollView.getVisibility() == View.GONE) {
            productsScrollView.setVisibility(View.VISIBLE);
            item.setIcon(R.drawable.ic_action_navigation_collapse);
            Preferences.setPref(getActivity(), Preferences.SHOW_ADV_DIRECTIONS, true);
        } else {//from   ww w  .j a  v  a 2 s  .c o m
            productsScrollView.setVisibility(View.GONE);
            item.setIcon(R.drawable.ic_action_navigation_expand);
            Preferences.setPref(getActivity(), Preferences.SHOW_ADV_DIRECTIONS, false);
        }

        return true;
    case R.id.action_swap_locations:
        // get location icons to be swapped as well
        final ImageView fromStatusButton = (ImageView) mView.findViewById(R.id.fromStatusButton);
        final Drawable icon = ((ImageView) mView.findViewById(R.id.toStatusButton)).getDrawable();

        // swap location objects and drawables
        Location tmp = getLocation(FavLocation.LOC_TYPE.TO);
        if (!mGpsPressed) {
            setLocation(getLocation(FavLocation.LOC_TYPE.FROM), FavLocation.LOC_TYPE.TO,
                    fromStatusButton.getDrawable());
        } else {
            // GPS currently only supports from location, so don't swap it
            clearLocation(FavLocation.LOC_TYPE.TO);
        }
        setLocation(tmp, FavLocation.LOC_TYPE.FROM, icon);

        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:es.upv.riromu.arbre.main.MainActivity.java

/******************************************/
public void sendData(View view) {
    ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    try {/*ww w.j  ava 2 s .c om*/

        Calendar c = Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
        String formattedDate = df.format(c.getTime());
        String result = "";

        if (image_uri != null) {
            UploadImageTask task1 = new UploadImageTask(this, new Callback() {
                public void run(Object result) {
                    upload = result.toString();
                    //do something here with the result
                }
            });

            if (state[PICK_IMAGE]) {
                File f = new File(Util.getRealPathFromURI(this, image_uri));
                task1.execute(f, 1);
            } else {
                File f = new File(image_uri.getPath());
                task1.execute(f, 1);
            }

            UploadImageTask task2 = new UploadImageTask(this, new Callback() {
                public void run(Object result) {
                    //do something here with the result
                    upload = result.toString();
                }
            });

            File f = createJSONFile(histograma);
            task2.execute(f, 2);

            UploadImageTask task3 = new UploadImageTask(this, new Callback() {
                public void run(Object result) {
                    //do something here with the result
                    upload = result.toString();

                }
            });
            ImageView imv = (ImageView) findViewById(R.id.image_intro);
            Bitmap bm = ((BitmapDrawable) imv.getDrawable()).getBitmap();
            f = createImageFile(bm);
            task3.execute(f, 3);

            UploadImageTask task4 = new UploadImageTask(this, new Callback() {
                public void run(Object result) {
                    //do something here with the result
                    upload = result.toString();

                }
            });

            f = createJSONFile(mascara);
            task4.execute(f, 4);

            UploadImageTask task5 = new UploadImageTask(this, new Callback() {
                public void run(Object result) {
                    //do something here with the result
                    upload = result.toString();

                }
            });

            f = createImageFile(histogram);
            task5.execute(f, 5);
            resetVariables();
        }

    } catch (Exception e) {
        Log.e(TAG, "Error" + e.getMessage());
    }

}

From source file:eu.faircode.netguard.AdapterLog.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    long time = cursor.getLong(colTime);
    int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
    int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
    String flags = cursor.getString(colFlags);
    String saddr = cursor.getString(colSAddr);
    int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort));
    String daddr = cursor.getString(colDAddr);
    int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
    String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName));
    int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
    String data = cursor.getString(colData);
    int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed));
    int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection));
    int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive));

    // Get views//  w  ww. j  a v a 2 s . c om
    TextView tvTime = view.findViewById(R.id.tvTime);
    TextView tvProtocol = view.findViewById(R.id.tvProtocol);
    TextView tvFlags = view.findViewById(R.id.tvFlags);
    TextView tvSAddr = view.findViewById(R.id.tvSAddr);
    TextView tvSPort = view.findViewById(R.id.tvSPort);
    final TextView tvDaddr = view.findViewById(R.id.tvDAddr);
    TextView tvDPort = view.findViewById(R.id.tvDPort);
    final TextView tvOrganization = view.findViewById(R.id.tvOrganization);
    final ImageView ivIcon = view.findViewById(R.id.ivIcon);
    TextView tvUid = view.findViewById(R.id.tvUid);
    TextView tvData = view.findViewById(R.id.tvData);
    ImageView ivConnection = view.findViewById(R.id.ivConnection);
    ImageView ivInteractive = view.findViewById(R.id.ivInteractive);

    // Show time
    tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));

    // Show connection type
    if (connection <= 0)
        ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked);
    else {
        if (allowed > 0)
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on);
        else
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable());
        DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff);
    }

    // Show if screen on
    if (interactive <= 0)
        ivInteractive.setImageDrawable(null);
    else {
        ivInteractive.setImageResource(R.drawable.screen_on);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable());
            DrawableCompat.setTint(wrap, colorOn);
        }
    }

    // Show protocol name
    tvProtocol.setText(Util.getProtocolName(protocol, version, false));

    // SHow TCP flags
    tvFlags.setText(flags);
    tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE);

    // Show source and destination port
    if (protocol == 6 || protocol == 17) {
        tvSPort.setText(sport < 0 ? "" : getKnownPort(sport));
        tvDPort.setText(dport < 0 ? "" : getKnownPort(dport));
    } else {
        tvSPort.setText(sport < 0 ? "" : Integer.toString(sport));
        tvDPort.setText(dport < 0 ? "" : Integer.toString(dport));
    }

    // Application icon
    ApplicationInfo info = null;
    PackageManager pm = context.getPackageManager();
    String[] pkg = pm.getPackagesForUid(uid);
    if (pkg != null && pkg.length > 0)
        try {
            info = pm.getApplicationInfo(pkg[0], 0);
        } catch (PackageManager.NameNotFoundException ignored) {
        }

    if (info == null)
        ivIcon.setImageDrawable(null);
    else {
        if (info.icon <= 0)
            ivIcon.setImageResource(android.R.drawable.sym_def_app_icon);
        else {
            ivIcon.setHasTransientState(true);
            final ApplicationInfo finalInfo = info;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        Drawable drawable = context.getPackageManager()
                                .getApplicationIcon(finalInfo.packageName);
                        final Drawable scaledDrawable;
                        if (drawable instanceof BitmapDrawable) {
                            Bitmap original = ((BitmapDrawable) drawable).getBitmap();
                            Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false);
                            scaledDrawable = new BitmapDrawable(context.getResources(), scaled);
                        } else
                            scaledDrawable = drawable;

                        new Handler(context.getMainLooper()).post(new Runnable() {
                            @Override
                            public void run() {
                                ivIcon.setImageDrawable(scaledDrawable);
                                ivIcon.setHasTransientState(false);
                            }
                        });
                    } catch (Throwable ex) {
                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        new Handler(context.getMainLooper()).post(new Runnable() {
                            @Override
                            public void run() {
                                ivIcon.setImageDrawable(null);
                                ivIcon.setHasTransientState(false);
                            }
                        });
                    }
                }
            });
        }
    }

    boolean we = (android.os.Process.myUid() == uid);

    // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
    uid = uid % 100000; // strip off user ID
    if (uid == -1)
        tvUid.setText("");
    else if (uid == 0)
        tvUid.setText(context.getString(R.string.title_root));
    else if (uid == 9999)
        tvUid.setText("-"); // nobody
    else
        tvUid.setText(Integer.toString(uid));

    // Show source address
    tvSAddr.setText(getKnownAddress(saddr));

    // Show destination address
    if (!we && resolve && !isKnownAddress(daddr))
        if (dname == null) {
            tvDaddr.setText(daddr);
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvDaddr, true);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return InetAddress.getByName(args[0]).getHostName();
                    } catch (UnknownHostException ignored) {
                        return args[0];
                    }
                }

                @Override
                protected void onPostExecute(String name) {
                    tvDaddr.setText(">" + name);
                    ViewCompat.setHasTransientState(tvDaddr, false);
                }
            }.execute(daddr);
        } else
            tvDaddr.setText(dname);
    else
        tvDaddr.setText(getKnownAddress(daddr));

    // Show organization
    tvOrganization.setVisibility(View.GONE);
    if (!we && organization) {
        if (!isKnownAddress(daddr))
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvOrganization, true);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return Util.getOrganization(args[0]);
                    } catch (Throwable ex) {
                        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        return null;
                    }
                }

                @Override
                protected void onPostExecute(String organization) {
                    if (organization != null) {
                        tvOrganization.setText(organization);
                        tvOrganization.setVisibility(View.VISIBLE);
                    }
                    ViewCompat.setHasTransientState(tvOrganization, false);
                }
            }.execute(daddr);
    }

    // Show extra data
    if (TextUtils.isEmpty(data)) {
        tvData.setText("");
        tvData.setVisibility(View.GONE);
    } else {
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
}

From source file:com.shopify.buy.ui.ProductImagePagerAdapter.java

@Override
public View getView(final int pos, ViewPager pager) {
    Context context = pager.getContext();
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.view_product_image, pager, false);
    layout.setTag(pos);/*  w  w  w. ja va 2 s.com*/

    final View imageLoadingIndicator = layout.findViewById(R.id.image_loading_indicator);
    final ImageView imageView = (ImageView) layout.findViewById(R.id.image);

    if (bitmaps == null) {
        bitmaps = new Bitmap[images.size()];
        Arrays.fill(bitmaps, null);
    }

    final boolean needBitmap = bitmaps[pos] == null;
    if (!needBitmap) {
        imageLoadingIndicator.setVisibility(View.INVISIBLE);
        imageView.setImageBitmap(bitmaps[pos]);

    } else {
        // We don't ask Picasso to show a placeholder because we want to scale the placeholder differently than
        // the product image. The placeholder should be displayed using CENTER_INSIDE, while the image should be
        // loaded using Picasso's fit() request method (to reduce memory usage during decoding) and then cropped
        // or fitted into the target view.
        String imageUrl = stripQueryFromUrl(images.get(pos).getSrc());
        ImageUtility.loadRemoteImageIntoViewWithoutSize(Picasso.with(context), imageUrl, imageView, maxWidth,
                maxHeight, false, new Callback() {
                    @Override
                    public void onSuccess() {
                        bitmaps[pos] = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
                        imageLoadingIndicator.setVisibility(View.INVISIBLE);
                        addBackgroundColor(pos);
                    }

                    @Override
                    public void onError() {
                        imageLoadingIndicator.setVisibility(View.VISIBLE);
                    }
                });
    }

    return layout;
}

From source file:com.thingsee.tracker.MainActivity.java

@Override
public void onMapReady(GoogleMap map) {
    mMap = map;// w ww.  j  a  v a2s . c  o  m

    TileProvider wmsTileProvider = TileProviderFactory.getKapsiWmsTileProvider();
    mMap.addTileOverlay(new TileOverlayOptions().tileProvider(wmsTileProvider).fadeIn(true));

    initGoogleMap();

    trackerList = (HorizontalScrollView) this.findViewById(R.id.tracker_scroll_area);
    mTrackerItemLayout = (LinearLayout) findViewById(R.id.trackers);

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mainari, 16));
    Marker mark = mMap.addMarker(new MarkerOptions().position(mainari));

    ImageView locateButton = (ImageView) findViewById(R.id.app_icon);

    //set the ontouch listener
    locateButton.setOnTouchListener(new OnTouchListener() {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                ImageView view = (ImageView) v;
                view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                if (onChildOnMapView) {
                    onUpPressed();
                } else {
                    userZoomAndPanOnMap = false;
                    zoomToBoundingBox();
                }
            case MotionEvent.ACTION_CANCEL: {
                ImageView view = (ImageView) v;
                //clear the overlay
                view.getDrawable().setColorFilter(mResources.getColor(R.color.white_effect),
                        PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            }

            return true;
        }
    });

    ImageView settingsButton = (ImageView) findViewById(R.id.header_settings_icon);

    //set the ontouch listener
    settingsButton.setOnTouchListener(new OnTouchListener() {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                ImageView view = (ImageView) v;
                //overlay is black with transparency of 0x77 (119)
                view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                final Dialog verificationQuery = new Dialog(mContext,
                        android.R.style.Theme_Translucent_NoTitleBar);
                verificationQuery.requestWindowFeature(Window.FEATURE_NO_TITLE);
                verificationQuery.setCancelable(false);
                verificationQuery.setContentView(R.layout.request_admin_code);
                ClearTextView ok = (ClearTextView) verificationQuery.findViewById(R.id.ok);
                ok.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        verificationQuery.dismiss();
                        EditText code = (EditText) verificationQuery.findViewById(R.id.verification_code);
                        if (code.getText().toString().equalsIgnoreCase("password")) {
                            Intent intent = new Intent(MainActivity.this, MenuActivity.class);
                            startActivity(intent);
                        }
                    }
                });
                ClearTextView cancel = (ClearTextView) verificationQuery.findViewById(R.id.cancel);
                cancel.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        verificationQuery.dismiss();
                    }
                });
                verificationQuery.show();
                verificationQuery.getWindow().setDimAmount(0.5f);
                verificationQuery.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            case MotionEvent.ACTION_CANCEL: {
                ImageView view = (ImageView) v;
                //clear the overlay
                view.getDrawable().setColorFilter(mResources.getColor(R.color.white_effect),
                        PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            }

            return true;
        }
    });

    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng position) {
            if (onChildOnMapView) {
                if (trackerModelWithMarker != null) {
                    trackerModelWithMarker.getMarker().showInfoWindow();
                }
            }
        }
    });

    mMap.setOnMarkerClickListener(new OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            if (trackersActive) {
                LatLng latlng = marker.getPosition();
                userZoomAndPanOnMap = false;
                if ((latlng.latitude == mainari.latitude) && (latlng.longitude == mainari.longitude)) {
                    if (onChildOnMapView) {
                        if (trackerModelWithMarker != null) {
                            trackerModelWithMarker.getMarker().showInfoWindow();
                        }
                    }
                } else {
                    if (!onChildOnMapView) {
                        trackerModelWithMarker = null;
                        // Zoom to marker tapped
                        zoomToMarker(latlng);
                        //Remove other markers
                        for (String key : trackers.keySet()) {
                            TrackerModel trackerModel = trackers.get(key);
                            if (trackerModel.getLatestLatLng() != null) {
                                if ((trackerModel.getLatestLatLng().latitude == latlng.latitude)
                                        && (trackerModel.getLatestLatLng().longitude == latlng.longitude)) {
                                    focusOnChildOnMap(trackerModel.getSerialNumber());
                                    trackerModelWithMarker = trackerModel;
                                    trackerModelWithMarker.getMarker().showInfoWindow();
                                }
                            }
                        }
                    } else {
                        trackerModelWithMarker.getMarker().showInfoWindow();
                        for (String key : trackers.keySet()) {
                            TrackerModel trackerModel = trackers.get(key);
                            if (trackerModel.getLatestLatLng() != null) {
                                if ((trackerModel.getLatestLatLng().latitude == latlng.latitude)
                                        && (trackerModel.getLatestLatLng().longitude == latlng.longitude)) {
                                    onBackPressed();
                                }
                            }
                        }
                    }
                }
            }
            return true;
        }
    });
    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

        // Defines the contents of the InfoWindow
        @Override
        public View getInfoContents(Marker arg0) {

            // Getting view from the layout file info_window_layout
            View v = null;

            for (String key : trackers.keySet()) {
                TrackerModel trackerModel = trackers.get(key);
                if (trackerModel.getLatestLatLng() != null) {
                    if ((trackerModel.getLatestLatLng().latitude == arg0.getPosition().latitude)
                            && (trackerModel.getLatestLatLng().longitude == arg0.getPosition().longitude)) {
                        v = getLayoutInflater().inflate(R.layout.info_window, null);
                        trackerModelWithMarker = trackerModel;
                        TextView trackerAccuracy = (TextView) v
                                .findViewById(R.id.tracker_marker_popup_accuracy);
                        if (trackerModelWithMarker.getAccuracy() != -1) {
                            trackerAccuracy
                                    .setText(String.format(mResources.getString(R.string.tracker_accuracy),
                                            trackerModelWithMarker.getAccuracy()));
                        } else {
                            trackerAccuracy.setText(
                                    String.format(mResources.getString(R.string.tracker_accuracy), 0.0f));
                        }
                        TextView trackerDistanceTs = (TextView) v
                                .findViewById(R.id.tracker_marker_popup_update_timestamp);
                        if (trackerModelWithMarker.getLastLocationUpdate() != 0) {
                            String timeStampText = Utilities.getSmartTimeStampString(mContext, mResources,
                                    trackerModelWithMarker.getLastLocationUpdate());
                            trackerDistanceTs.setText(
                                    mResources.getString(R.string.tracker_timestamp) + " " + timeStampText);
                        } else {
                            trackerDistanceTs.setText(mResources.getString(R.string.tracker_timestamp) + " - ");
                        }
                        trackerInfoWindow = v;
                    }
                }
            }
            // Returning the view containing InfoWindow contents
            return v;
        }
    });
    IntentFilter statusIntentFilter = new IntentFilter(CommonConstants.BROADCAST_ACTION);
    statusIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
    mFetchCloudDataStateReceiver = new FetchCloudDataStateReceiver();
    LocalBroadcastManager.getInstance(this).registerReceiver(mFetchCloudDataStateReceiver, statusIntentFilter);

    mapLoaded = true;
    if (splashReady) {
        mSplashHandler.postDelayed(splashScreenOffFromDisplay, 0);
    }
}