Example usage for android.graphics.drawable Drawable createFromPath

List of usage examples for android.graphics.drawable Drawable createFromPath

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable createFromPath.

Prototype

@Nullable
public static Drawable createFromPath(String pathName) 

Source Link

Document

Create a drawable from file path name.

Usage

From source file:babybear.akbquiz.ConfigActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUESTCODE_IMAGE) {
        if (resultCode == RESULT_OK) {
            Bundle d = data.getExtras();
            Set<String> keys = d.keySet();
            for (String key : keys) {
                Log.d(TAG, "key : " + key + " values : " + d.get(key));
            }//from w w  w .  j a  v a 2  s . co  m
            cfgEditor.putBoolean(Database.KEY_use_custom_background, true);
            cfgEditor.commit();
            cfgflipper.setBackgroundDrawable(Drawable.createFromPath(customBgImage.getPath()));
        }
        return;
    }

    if (weiboSsoHandler != null) {
        weiboSsoHandler.authorizeCallBack(requestCode, resultCode, data);
    }
}

From source file:com.intel.xdk.device.Device.java

@Override
public void initialize(CordovaInterface cordova, final CordovaWebView webView) {
    super.initialize(cordova, webView);

    this.activity = cordova.getActivity();
    this.webView = webView;

    //remote site support
    remoteLayout = new AbsoluteLayout(activity);
    remoteLayout.setBackgroundColor(Color.BLACK);
    //hide the remote site display until needed
    remoteLayout.setVisibility(View.GONE);
    //create the close button
    remoteClose = new ImageButton(activity);
    remoteClose.setBackgroundColor(Color.TRANSPARENT);
    Drawable remoteCloseImage = null;/*from   w w  w  . jav  a2s  . co  m*/
    remoteCloseImage = activity.getResources().getDrawable(
            activity.getResources().getIdentifier("remote_close", "drawable", activity.getPackageName()));

    File remoteCloseImageFile = new File(activity.getFilesDir(), "_intelxdk/remote_close.png");
    if (remoteCloseImageFile.exists()) {
        remoteCloseImage = (Drawable.createFromPath(remoteCloseImageFile.getAbsolutePath()));
    } else {
        remoteCloseImage = (activity.getResources().getDrawable(
                activity.getResources().getIdentifier("remote_close", "drawable", activity.getPackageName())));
    }

    //set the button image
    //remoteClose.setImageDrawable(remoteCloseImage);
    remoteClose.setBackgroundDrawable(remoteCloseImage);
    //set up the button click action
    remoteClose.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            closeRemoteSite();
        }
    });
    //add the close button
    remoteLayout.addView(remoteClose);

    final ViewGroup parent = (ViewGroup) webView.getEngine().getView().getParent();
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (parent != null) {
                //add layout to activity root layout
                parent.addView(remoteLayout, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER));

            }
        }
    });

    //Initialize the orientation.
    lastOrientation = "unknown";

    //Listen to the orientation change.
    OrientationEventListener listener = new OrientationEventListener(activity) {

        @Override
        public void onOrientationChanged(int orientation) {
            //Log.d("orientation","orientation: " + orientation);

            String currentOrientation = "unknown";
            boolean orientationChanged = false;
            //int displayOrientation = 0;

            if (orientation > 345 || orientation < 15) {
                currentOrientation = "portrait";
                displayOrientation = 0;
            } else if (orientation > 75 && orientation < 105) {
                currentOrientation = "landscape";
                displayOrientation = 90;
            } else if (orientation > 165 && orientation < 195) {
                currentOrientation = "portrait";
                displayOrientation = 180;
            } else if (orientation > 255 && orientation < 285) {
                currentOrientation = "landscape";
                displayOrientation = -90;
            }

            if (currentOrientation.equals("unknown")) {
                currentOrientation = lastOrientation;
            }

            if (!currentOrientation.equals(lastOrientation)) {
                orientationChanged = true;
                Log.d("orientation", "Orientation changes from " + lastOrientation + " to " + currentOrientation
                        + ", current orientation: " + orientation + ".");
            }

            if (orientationChanged) {
                String js = "javascript:try{intel.xdk.device.orientation='" + displayOrientation
                        + "';}catch(e){}var e = document.createEvent('Events');e.initEvent('intel.xdk.device.orientation.change', true, true);e.success=true;e.orientation='"
                        + displayOrientation + "';document.dispatchEvent(e);";
                injectJS(js);
            }

            lastOrientation = currentOrientation;
        }

    };

    listener.enable();
    registerScreenStatusReceiver();

    //cache references to methods for use in injectJS
    try {
        evaluateJavascript = webView.getClass().getMethod("evaluateJavascript", String.class,
                ValueCallback.class);
    } catch (Exception e) {
    }

    try {
        sendJavascript = webView.getClass().getMethod("sendJavascript", String.class);
    } catch (Exception e) {
    }

    emptyVC = new ValueCallback<String>() {
        @Override
        public void onReceiveValue(String s) {
        }
    };

}

From source file:th.in.ffc.person.PersonMainActivity.java

@Override
public void onResume() {
    super.onResume();
    if (mImage != null) {
        File path = new File(mPhotoPath);
        if (path.exists())
            mImage.setImageDrawable(Drawable.createFromPath(mPhotoPath));
    }//  www . jav  a  2 s.  com
}

From source file:com.esri.arcgisruntime.sample.picturemarkersymbols.MainActivity.java

/**
 * Create a picture marker symbol from an image on disk. Called from checkSaveResourceToExternalStorage() or
 * onRequestPermissionsResult which validate required external storage and permissions
 *//*w w  w  .j  av a 2s  .  c o m*/
private void createPictureMarkerSymbolFromFile() {

    //[DocRef: Name=Picture Marker Symbol File-android, Category=Fundamentals, Topic=Symbols and Renderers]
    //Create a picture marker symbol from a file on disk
    BitmapDrawable pinBlankOrangeDrawable = (BitmapDrawable) Drawable.createFromPath(mPinBlankOrangeFilePath);
    final PictureMarkerSymbol pinBlankOrangeSymbol = new PictureMarkerSymbol(pinBlankOrangeDrawable);
    //Optionally set the size, if not set the image will be auto sized based on its size in pixels,
    //its appearance would then differ across devices with different resolutions.
    pinBlankOrangeSymbol.setHeight(20);
    pinBlankOrangeSymbol.setWidth(20);
    //Optionally set the offset, to align the base of the symbol aligns with the point geometry
    pinBlankOrangeSymbol.setOffsetY(10); //The image used has not buffer and therefore the Y offset is height/2
    pinBlankOrangeSymbol.loadAsync();
    //[DocRef: END]
    pinBlankOrangeSymbol.addDoneLoadingListener(new Runnable() {
        @Override
        public void run() {
            //add a new graphic with the same location as the initial viewpoint
            Point pinBlankOrangePoint = new Point(-228835, 6550763, SpatialReferences.getWebMercator());
            Graphic pinBlankOrangeGraphic = new Graphic(pinBlankOrangePoint, pinBlankOrangeSymbol);
            mGraphicsOverlay.getGraphics().add(pinBlankOrangeGraphic);
        }
    });

}

From source file:com.quuzz.tbg.recyclerview.CustomAdapter.java

@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
    Log.d(TAG, "Element " + position + " set.");

    // Get element from your dataset at this position and replace the contents of the view
    // with that element
    viewHolder.getTextView().setText(mDataSet[position].getName());

    // bind image to viewHolder
    //        Drawable imgDrawable =  context.getResources().getDrawable(R.drawable.tb_1, null);
    //        viewHolder.getImageView().setImageDrawable(imgDrawable);

    Drawable imgDrawable = Drawable.createFromPath("/data/" + Environment.getDataDirectory() + "/"
            + context.getPackageName() + "/files/file_" + mDataSet[position].getTbId());
    Bitmap bitmap = ((BitmapDrawable) imgDrawable).getBitmap();
    // Scale it to 50 x 50
    Drawable scaledDrawable = new BitmapDrawable(context.getResources(), resizeImageForImageView(bitmap, true));
    viewHolder.getImageView().setImageDrawable(scaledDrawable);

    //        ByteArrayInputStream is = new ByteArrayInputStream(mDataSet[position].getImageData());
    //        Bitmap bitmap = BitmapFactory.decodeStream(is);
    //        viewHolder.getImageView().setImageBitmap(bitmap);

}

From source file:org.webinos.app.wrt.ui.WidgetListActivity.java

private static Store readStore(Context ctx, JSONObject json) {
    Store result = new Store();
    try {//from  w  ww.  java2 s  .  c o m
        result.name = json.getString("name");
        result.description = json.getString("description");
        result.location = Uri.parse(json.getString("location"));
        String iconURL = json.getString("logo");
        try {
            File iconFile = ModuleUtils.getResource(new URI(iconURL), true);
            result.icon = Drawable.createFromPath(iconFile.getAbsolutePath());
        } catch (IOException e) {
            result.icon = ctx.getResources().getDrawable((R.drawable.webinos_icon));
        } catch (URISyntaxException e) {
            result.icon = ctx.getResources().getDrawable((R.drawable.webinos_icon));
        }
    } catch (JSONException e) {
        result = null;
    }
    return result;
}

From source file:ca.ualberta.cs.cmput301w15t04team04project.FragmentEditItem2.java

/**
 * <b>This part of code is from:</b><br>
 * {@link http://stackoverflow.com/questions/4830711/how-to-convert-a-image-into-base64-string}<br>
 * @since March 26/*w  w w .  ja v a  2  s .c o  m*/
 */
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
        if (resultCode == -1) {

            Drawable drawable = Drawable.createFromPath(imageFileUri.getPath());
            Bitmap bitmap = BitmapFactory.decodeFile(imageFileUri.getPath());

            myActivity.setReceiptBitmap(bitmap, 1);

            ImageButton button = (ImageButton) thisview.findViewById(R.id.addRecieptImageButton);
            button.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 256, 256, false));

        }
    }

}

From source file:babybear.akbquiz.ConfigActivity.java

/**
 * ?/*from w  ww .  j  a  v  a  2 s  .  c  om*/
 */
private void init() {

    ToggleButton bgm_toggle = (ToggleButton) findViewById(R.id.bgm_switch);
    ToggleButton sound_toggle = (ToggleButton) findViewById(R.id.sound_switch);
    ToggleButton vibration_toggle = (ToggleButton) findViewById(R.id.config_vibration_switch);
    SeekBar bgm_vol = (SeekBar) findViewById(R.id.bgm_volume);
    SeekBar sound_vol = (SeekBar) findViewById(R.id.sound_volume);
    Button config_playlist = (Button) findViewById(R.id.config_playlist);

    bgm_toggle.setChecked(sp_cfg.getBoolean(Database.KEY_switch_bg, true));
    sound_toggle.setChecked(sp_cfg.getBoolean(Database.KEY_switch_sound, true));
    vibration_toggle.setChecked(sp_cfg.getBoolean(Database.KEY_switch_vibration, true));
    bgm_vol.setProgress(sp_cfg.getInt(Database.KEY_vol_bg, 10));
    sound_vol.setProgress(sp_cfg.getInt(Database.KEY_vol_sound, 10));

    // ?
    loopmode = sp_cfg.getInt(Database.KEY_bgm_loopmode, BgMusic.MODE_LOOP);
    switch (loopmode) {
    case BgMusic.MODE_LOOP:
        ((Button) findViewById(R.id.config_loopmode)).setText(R.string.config_loop);
    case BgMusic.MODE_RANDOM:
        ((Button) findViewById(R.id.config_loopmode)).setText(R.string.config_random);
    case BgMusic.MODE_SINGLE:
        ((Button) findViewById(R.id.config_loopmode)).setText(R.string.config_single);
    }
    // ?

    if (sp_cfg.getBoolean(Database.KEY_use_custom_background, false)) {
        cfgflipper.setBackgroundDrawable(Drawable.createFromPath(customBgImage.getPath()));
    }

    OnClickListener clickListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.bgm_switch:
                boolean isBgOn = ((ToggleButton) v).isChecked();
                cfgEditor.putBoolean(Database.KEY_switch_bg, isBgOn);
                Message msg = new Message();
                msg.what = isBgOn ? 1 : 0;
                msg.arg1 = BgMusic.BGHandler.SWITCH_CHANGE;
                BgMusic.bgHandler.sendMessage(msg);
                break;
            case R.id.sound_switch:
                boolean isSoundOn = ((ToggleButton) v).isChecked();
                cfgEditor.putBoolean(Database.KEY_switch_sound, isSoundOn);
                MainMenu.se.setSwitch(isSoundOn);
                break;
            case R.id.config_vibration_switch:
                boolean isVibOn = ((ToggleButton) v).isChecked();
                cfgEditor.putBoolean(Database.KEY_switch_vibration, isVibOn);
                break;
            case R.id.config_playlist:
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                    if (!isPlaylistChanged) {
                        loadPlaylistEditor();
                    }

                    cfgflipper.showNext();

                } else {
                    Toast.makeText(ConfigActivity.this, R.string.sdcard_unavailable, Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.config_ranking:
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("market://details?id=" + getPackageName()));
                startActivity(intent);
                break;

            case R.id.config_back:
                cfgEditor.commit();
                finish();
                break;

            case R.id.config_musiclist_back:
            case R.id.config_playlist_back:
                cfgflipper.showPrevious();
                break;

            case R.id.config_update:
                verCode = getVerCode(ConfigActivity.this);
                verName = getVerName(ConfigActivity.this);
                if (getServerVer()) {
                    if (newVerCode > verCode) {
                        doNewVersionUpdate(); // 
                    } else {
                        notNewVersionShow(); // ???
                    }
                }

                break;
            case R.id.config_loopmode:
                changeLoopMode();
                break;
            case R.id.config_quiz_submit:
                Intent intent1 = new Intent(ConfigActivity.this, CollectQuiz.class);
                startActivity(intent1);
                break;
            case R.id.config_change_bgimage:
                customBgImage();
                break;
            case R.id.config_restore_bgimage:
                restoreBgImage();
                break;
            case R.id.call_calendar_editor:
                Intent calendar = new Intent(ConfigActivity.this, CalendarEditor.class);
                startActivity(calendar);
                break;
            case R.id.who_are_we:
                if (aboutFHS == null) {
                    aboutFHS = (new AlertDialog.Builder(ConfigActivity.this)).setTitle(R.string.who_are_we)
                            .setMessage(R.string.about_fhs).setIcon(R.drawable.fhs_logo_48)
                            .setPositiveButton(android.R.string.ok, null).create();
                }
                aboutFHS.show();
                break;
            case R.id.licence:
                if (license == null) {
                    license = (new AlertDialog.Builder(ConfigActivity.this)).setTitle(R.string.license_title)
                            .setIcon(android.R.drawable.stat_sys_warning).setMessage(R.string.license)
                            .setPositiveButton(android.R.string.ok, null).create();
                }
                license.show();
                break;
            }
        }

    };

    bgm_toggle.setOnClickListener(clickListener);
    sound_toggle.setOnClickListener(clickListener);
    vibration_toggle.setOnClickListener(clickListener);
    config_playlist.setOnClickListener(clickListener);

    ((Button) findViewById(R.id.config_back)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.config_musiclist_back)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.config_playlist_back)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.config_update)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.config_quiz_submit)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.config_ranking)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.config_loopmode)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.config_change_bgimage)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.config_restore_bgimage)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.call_calendar_editor)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.who_are_we)).setOnClickListener(clickListener);
    ((Button) findViewById(R.id.licence)).setOnClickListener(clickListener);

    OnSeekBarChangeListener l_seekbar = new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            switch (arg0.getId()) {
            case R.id.bgm_volume:
                cfgEditor.putInt(Database.KEY_vol_bg, arg1);
                Message msg = new Message();
                msg.what = arg1;
                msg.arg1 = BgMusic.BGHandler.VOL_CHANGE;
                BgMusic.bgHandler.sendMessage(msg);
                break;
            case R.id.sound_volume:
                cfgEditor.putInt(Database.KEY_vol_sound, arg1);
                MainMenu.se.setVolume(arg1);
                break;
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }

    };
    bgm_vol.setOnSeekBarChangeListener(l_seekbar);
    sound_vol.setOnSeekBarChangeListener(l_seekbar);
}

From source file:th.in.ffc.person.PersonMainActivity.java

public void doSetupImage() {

    String name = getPcuCode().concat(mPid).concat("_720p.jpg");
    File pick = new File(FamilyFolderCollector.PHOTO_DIRECTORY_PERSON, name);
    mPhotoPath = pick.getAbsolutePath();

    mImage = (ImageView) findViewById(R.id.image);
    mImage.setOnClickListener(new View.OnClickListener() {

        @Override//from ww  w . j a va2  s  . c  o  m
        public void onClick(View v) {
            File path = new File(mPhotoPath);
            if (path.exists())
                mImage.setImageDrawable(Drawable.createFromPath(mPhotoPath));

            if (qa != null && mNotifacate != null) {
                qa.show(mNotifacate);
            }
        }
    });
    mImage.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            mPhotoTaker.doShowDialog();
            return true;
        }
    });

    if (pick.exists())
        mImage.setImageDrawable(Drawable.createFromPath(mPhotoPath));

    mPhotoTaker = new PhotoTaker(this, FamilyFolderCollector.PHOTO_DIRECTORY_PERSON, name);
    mPhotoTaker.setCropfinishListener(this);

}

From source file:th.in.ffc.person.visit.VisitMainActivity.java

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    // Query for Principle DX
    if (!TextUtils.isEmpty(mVisitNo)) {
        ContentResolver cr = getContentResolver();
        Cursor c = cr.query(VisitDiag.CONTENT_URI, new String[] { VisitDiag.CODE, VisitDiag.TYPE },
                "visitno=? AND dxtype='01'", new String[] { mVisitNo, }, VisitDiag.DEFAULT_SORTING);
        if (c.moveToFirst()) {
            mPDX = c.getString(0);//from ww  w. jav a 2 s  .co  m
            mDX.setText(mPDX);
            mDX.setTag((c.getCount() > 1 ? "tag" : null));
            mDX.setVisibility(View.VISIBLE);
            mDX.setOnClickListener(dxListener);
        } else {
            mPDX = null;
            mDX.setVisibility(View.INVISIBLE);
            mDX.setOnClickListener(null);
        }

        File img = new File(FamilyFolderCollector.PHOTO_DIRECTORY_SERVICE, mVisitNo.concat(".jpg"));
        if (img.exists())
            mVisitImage.setImageDrawable(Drawable.createFromPath(img.getAbsolutePath()));
    }
}