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:Main.java

public static Drawable getDrawableFromFile(String fileName) {
    Drawable d = Drawable.createFromPath(getAbsoluteFilePath(fileName));
    return d;
}

From source file:Main.java

public static boolean checkAndSetHomeWidget3(ImageButton ib) {
    boolean result = false;
    Drawable d = Drawable.createFromPath(CUST_PATH + HOME_WIDGET3_FILE_NAME);
    if (d != null) {
        ib.setImageDrawable(d);//from  w  w w. j a  v a 2  s .  c o m

        result = true;
    }

    return result;
}

From source file:Main.java

/**
 * launcher specific title//from   w ww.  j  a v  a  2s .  c  o  m
 * @param a
 * @param iv
 * @return
 */
public static boolean checkAndSetLauncherTitle(ImageView iv) {
    if (iv == null)
        return false;
    Drawable d = Drawable.createFromPath(CUST_PATH + LAUNCHER_LOGO_FILE_NAME);
    if (d != null) {
        iv.setImageDrawable(d);
        return true;
    } else
        return false;
}

From source file:Main.java

public static Drawable getDrawableFromFile(File pngFile) {

    return Drawable.createFromPath(pngFile.getPath());
}

From source file:org.jorge.lolin1.ui.activities.ChatRoomActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getActionBar();
    friendName = null;// w w  w .  j  av a  2 s .com
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(Boolean.TRUE);
        actionBar.setTitle(friendName = getIntent().getStringExtra(ChatOverviewActivity.KEY_FRIEND_NAME));
        try {
            actionBar
                    .setLogo(
                            Drawable.createFromPath(
                                    ProfileCacheableBitmapLoader
                                            .getPathByID(getApplicationContext(),
                                                    FriendManager.getInstance().findFriendByName(friendName)
                                                            .getStatus().getProfileIconId())
                                            .getAbsolutePath()));
        } catch (NullPointerException ex) {
            startActivity(new Intent(getApplicationContext(), ChatOverviewActivity.class));//Clicking notification with app closed
            finish();
            return;
        }
        actionBar.setDisplayUseLogoEnabled(Boolean.TRUE);
    }
    ChatNotificationManager.dismissNotifications(getApplicationContext(), friendName);
    setContentView(R.layout.activity_chat_room);

    final EditText messageContentsTextField = (EditText) findViewById(android.R.id.inputArea);

    messageContentsTextField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId != EditorInfo.IME_ACTION_DONE)
                return Boolean.FALSE;
            String contents = messageContentsTextField.getText().toString();
            if (TextUtils.isEmpty(contents))
                return Boolean.TRUE;
            adapter.add(new ChatMessageWrapper(contents, System.currentTimeMillis()));
            sendMessage(contents, friendName);
            messageContentsTextField.setText("");
            messageContentsTextField.requestFocus();
            return Boolean.TRUE;
        }

        private void sendMessage(String contents, String friendName) {
            new AsyncTask<String, Void, Void>() {
                @Override
                protected Void doInBackground(String... params) {
                    Friend target;
                    ChatMessageWrapper messageWrapper = new ChatMessageWrapper(params[0],
                            System.currentTimeMillis());
                    logString("debug", "Sending message " + params[0] + " to " + params[1]);
                    ChatBundleManager.addMessageToFriendChat(messageWrapper,
                            target = FriendManager.getInstance().findFriendByName(params[1]));
                    scrollListViewToBottom();
                    target.sendMessage(params[0]);
                    return null;
                }
            }.executeOnExecutor(Executors.newSingleThreadExecutor(), contents, friendName);
        }
    });

    conversationListView = (ListView) findViewById(android.R.id.list);
    conversationListView.setChoiceMode(AbsListView.CHOICE_MODE_NONE);

    logString("debug", "Calling adapter constructor");
    adapter = new ChatRoomAdapter(getApplicationContext(),
            FriendManager.getInstance().findFriendByName(friendName));

    if (!TextUtils.isEmpty(friendName))
        conversationListView.setAdapter(adapter);

    scrollListViewToBottom();

    registerLocalBroadcastReceiver();
    scrollListViewToBottom();
}

From source file:com.garage.payless.fragment.FragmentList.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.list_fragment, container, false);

    DelayAutoCompleteTextView bookTitle = (DelayAutoCompleteTextView) rootView.findViewById(R.id.book_title);
    bookTitle.setThreshold(4);/* w ww.  ja  va2  s.  com*/
    bookTitle.setAdapter(new GoodAutoCompleteAdapter(getActivity().getApplicationContext()));
    bookTitle.setLoadingIndicator((ProgressBar) rootView.findViewById(R.id.progress_bar));
    bookTitle.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            LinearLayout basketList = (LinearLayout) rootView.findViewById(R.id.basket);
            LinearLayout row = new LinearLayout(getActivity().getApplicationContext());
            row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            row.setOrientation(LinearLayout.HORIZONTAL);
            TextView valueTV = new TextView(getActivity().getApplicationContext());
            valueTV.setText((String) adapterView.getItemAtPosition(position));
            valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            row.addView(valueTV);
            ImageButton cancel = new ImageButton(getActivity().getApplicationContext());
            cancel.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            cancel.setImageDrawable(Drawable.createFromPath("@android:drawable/ic_menu_close_clear_cancel"));
            row.addView(cancel);
            basketList.addView(row);
        }
    });
    rootView.findViewById(R.id.create_btn).setOnClickListener(this);
    return rootView;
}

From source file:org.onepf.opfmaps.osmdroid.model.BitmapDescriptor.java

@NonNull
public Drawable createDrawable(@NonNull final Context context) {
    Drawable drawable = null;/*from w  ww. j  av a  2s.com*/
    switch (source) {
    case DEFAULT:
        drawable = createDefault(context, DEFAULT_HUE);
        break;
    case DEFAULT_HUE:
        drawable = createDefault(context, hue);
        break;
    case BITMAP:
        drawable = image == null ? null : new BitmapDrawable(context.getResources(), image);
        break;
    case ASSET:
    case FILE_NAME:
        drawable = createFromStream(context);
        break;
    case ABS_PATH:
        drawable = Drawable.createFromPath(path);
        break;
    case RES_ID:
        drawable = ContextCompat.getDrawable(context, resourceId);
        break;
    }

    return drawable == null ? createDefault(context, DEFAULT_HUE) : drawable;
}

From source file:com.yojiokisoft.yumekanow.fragment.CardFragment.java

/**
 * ??//ww w.  jav a 2 s .  c  o m
 */
@AfterViews
/*package*/void initFragment() {
    // ?
    List<CardEntity> cardList = null;
    int cardId = SettingDao.getInstance().getUseCard();
    if (cardId == -1) {
        cardList = new ArrayList<CardEntity>();
        cardList.add(getDefalutCard());
    } else {
        try {
            CardDao cardDao = new CardDao();
            cardList = cardDao.queryForEq("id", cardId);
            if (cardList.size() < 1) {
                cardList.add(getEmptyCard());
            }
        } catch (SQLException e) {
            MyUncaughtExceptionHandler.sendBugReport(mActivity, e);
        }
    }
    if (cardList == null) {
        return;
    }
    CardEntity card = cardList.get(0);

    mAffirmationText.setText(card.affirmationText);
    mAffirmationText.setTextColor(card.textColor);
    mAffirmationText.setTextSize(card.textSize);
    mAffirmationText.setShadowLayer(1.5f, 1.0f, 1.0f, card.shadowColor);

    DisplayMetrics metrics = new DisplayMetrics();
    mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int tabHeight = metrics.widthPixels / 7;
    MarginLayoutParams params = (MarginLayoutParams) mAffirmationText.getLayoutParams();
    params.leftMargin = MyResource.dip2Px(card.marginLeft);
    params.topMargin = MyResource.dip2Px(card.marginTop) - (tabHeight / 2);
    mAffirmationText.setLayoutParams(params);

    if (card.backImageType == BackImageEntity.IT_BITMAP) {
        Drawable drawable = Drawable.createFromPath(card.backImagePath);
        mBackImage.setBackgroundDrawable(drawable);
    } else {
        int resId = MyResource.getResourceIdByName(card.backImageResourceName);
        mBackImage.setBackgroundResource(resId);
    }
}

From source file:com.lithidsw.wallbox.app.wallsnap.WallSnapFragment.java

private Drawable getMainDrawable() {
    Drawable drawable = null;//from   w  w w .  j ava2 s  . c  o  m
    if (bundle != null) {
        if (bundleDrawable == null) {
            bundleDrawable = Drawable.createFromPath(bundle.getString(C.EXTRA_PATH));
            if (bundleDrawable != null) {
                drawable = bundleDrawable;
            }
        } else {
            drawable = bundleDrawable;
        }
    }

    if (drawable == null) {
        drawable = wm.getDrawable();
    }
    return drawable;
}

From source file:org.akvo.caddisfly.sensor.colorimetry.strip.ui.BrandInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_brand_info);

    final Activity activity = this;
    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);

    ImageView imageBrandLabel = (ImageView) findViewById(R.id.imageBrandLabel);

    // To start Camera
    Button buttonPrepareTest = (Button) findViewById(R.id.button_prepare);
    buttonPrepareTest.setOnClickListener(new View.OnClickListener() {
        @Override/*  ww w.  j a va  2  s  .c  o  m*/
        public void onClick(View view) {
            if (!ApiUtil.hasPermissions(activity, PERMISSIONS)) {
                ActivityCompat.requestPermissions(activity, PERMISSIONS, PERMISSION_ALL);
            } else {
                startCamera();
            }
        }
    });

    // To display Instructions
    Button buttonInstruction = (Button) findViewById(R.id.button_instructions);
    buttonInstruction.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getBaseContext(), InstructionActivity.class);
            intent.putExtra(Constant.UUID, mUuid);
            startActivity(intent);
        }
    });

    mUuid = getIntent().getStringExtra(Constant.UUID);

    if (mUuid != null) {
        StripTest stripTest = new StripTest();

        // Display the brand in title
        setTitle(stripTest.getBrand(mUuid).getName());

        //            try {
        //                imageBrandLabel.setBackgroundColor(Color.parseColor(stripTest.getBrand(this, mUuid).getBackground()));
        //            } catch (Exception ignored) {
        //
        //            }

        // Display the brand photo
        InputStream ims = null;
        try {
            Drawable drawable;
            String image = stripTest.getBrand(mUuid).getImage();

            if (image.contains(File.separator)) {
                if (!image.contains(".")) {
                    image = image + ".webp";
                }
                drawable = Drawable.createFromPath(image);
            } else {
                String path = getResources().getString(R.string.striptest_images);
                ims = getAssets().open(path + File.separator + image + ".webp");
                drawable = Drawable.createFromStream(ims, null);
            }

            imageBrandLabel.setImageDrawable(drawable);
            imageBrandLabel.setScaleType(stripTest.getBrand(mUuid).getImageScale().equals("centerCrop")
                    ? ImageView.ScaleType.CENTER_CROP
                    : ImageView.ScaleType.FIT_CENTER);
        } catch (Exception ex) {
            Timber.e(ex);
        } finally {
            if (ims != null) {
                try {
                    ims.close();
                } catch (IOException e) {
                    Timber.e(e);
                }
            }

        }

        JSONArray instructions = stripTest.getBrand(mUuid).getInstructions();
        if (instructions == null || instructions.length() == 0) {
            buttonInstruction.setVisibility(View.INVISIBLE);
        }
    }
}