Example #1
0
  private void initMenuButtons() {
    final int dividerHeight = (int) (2.0f * density);

    menuLayout.setOrientation(LinearLayout.VERTICAL);
    menuLayout.setBackgroundColor(Color.DKGRAY);
    menuLayout.setPadding(dividerHeight, 0, dividerHeight, 0);

    final PaintDrawable divider = new PaintDrawable(Color.WHITE);
    divider.setIntrinsicHeight(dividerHeight);
    menuLayout.setDividerDrawable(divider);
    menuLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);

    saveButton.setText("Save");
    saveButton.setTextSize(20);
    saveButton.setTextColor(this.getResources().getColorStateList(R.color.text_button_color));
    saveButton.setGravity(Gravity.LEFT);
    saveButton.setPadding(
        (int) (10.0f * density),
        (int) (2.0f * density),
        (int) (2.0f * density),
        (int) (10.0f * density));
    saveButton.setBackgroundColor(this.getResources().getColor(R.color.clear));
    menuLayout.addView(saveButton);

    shareButton.setText("Share");
    shareButton.setTextSize(20);
    shareButton.setTextColor(this.getResources().getColorStateList(R.color.text_button_color));
    shareButton.setGravity(Gravity.LEFT);
    shareButton.setPadding(
        (int) (10.0f * density),
        (int) (2.0f * density),
        (int) (2.0f * density),
        (int) (10.0f * density));
    shareButton.setBackgroundColor(this.getResources().getColor(R.color.clear));
    menuLayout.addView(shareButton);

    renameButton.setText("Rename");
    renameButton.setTextSize(20);
    renameButton.setTextColor(this.getResources().getColorStateList(R.color.text_button_color));
    renameButton.setGravity(Gravity.LEFT);
    renameButton.setPadding(
        (int) (10.0f * density),
        (int) (2.0f * density),
        (int) (2.0f * density),
        (int) (10.0f * density));
    renameButton.setBackgroundColor(this.getResources().getColor(R.color.clear));
    menuLayout.addView(renameButton);
  }
  /** Called when the activity is first created. */
  @SuppressLint("NewApi")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_deal_photo);
    mLinerLt = (LinearLayout) findViewById(R.id.newDealPhotoLinearLayout);
    Resources res = getResources();
    Drawable divider = res.getDrawable(R.drawable.image_divider);
    mLinerLt.setDividerDrawable(divider);
    mLinerLt.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    mImageBitmap = null;
    Button okBtn = (Button) findViewById(R.id.newdeal_photo_ok_btn);
    mapPhotos = new HashMap<String, Boolean>();
    okBtn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Bundle bnd = new Bundle();
            Intent res = new Intent();
            ArrayList<String> picsArr = new ArrayList<String>();
            for (Entry<String, Boolean> en : mapPhotos.entrySet()) {
              if (en.getValue() == true) picsArr.add(en.getKey());
            }
            bnd.putStringArrayList(PICS_ARRAY, picsArr);
            res.putExtras(bnd);
            setResult(Activity.RESULT_OK, res);
            finish();
          }
        });
    Button picBtn = (Button) findViewById(R.id.btnTakePic);
    setBtnListenerOrDisable(picBtn, mTakePicOnClickListener, MediaStore.ACTION_IMAGE_CAPTURE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
      mAlbumStorageDirFactory = new FroyoAlbumDirFactory();
    } else {
      mAlbumStorageDirFactory = new BaseAlbumDirFactory();
    }
  }
  public static void overrideStyle(Context context, AlertDialog dialog, boolean light) {
    // resources
    int resourceDialogTitleText =
        light ? R.color.dialog_title_text_light : R.color.dialog_title_text_dark;
    int resourceDialogTitleDivider =
        light ? R.color.dialog_title_divider_light : R.color.dialog_title_divider_dark;
    int resourceDialogMessageText =
        light ? R.color.dialog_message_text_light : R.color.dialog_message_text_dark;
    int resourceDialogButtonText =
        light ? R.color.dialog_button_text_light : R.color.dialog_button_text_dark;
    int resourceSelectorDialogButtonBg =
        light
            ? R.drawable.selector_dialog_button_bg_light
            : R.drawable.selector_dialog_button_bg_dark;
    int resourceShapeDialogDividerHorizontal =
        light
            ? R.drawable.shape_dialog_divider_horizontal_light
            : R.drawable.shape_dialog_divider_horizontal_dark;
    int resourceShapeDialogDividerVertical =
        light
            ? R.drawable.shape_dialog_divider_vertical_light
            : R.drawable.shape_dialog_divider_vertical_dark;

    // ids
    // final int parentPanel = context.getResources().getIdentifier("parentPanel", "id", "android");
    final int topPanel = context.getResources().getIdentifier("topPanel", "id", "android");
    final int contentPanel = context.getResources().getIdentifier("contentPanel", "id", "android");
    final int customPanel = context.getResources().getIdentifier("customPanel", "id", "android");
    final int buttonPanel = context.getResources().getIdentifier("buttonPanel", "id", "android");

    final int alertTitle = context.getResources().getIdentifier("alertTitle", "id", "android");
    final int titleDivider = context.getResources().getIdentifier("titleDivider", "id", "android");
    final int message = context.getResources().getIdentifier("message", "id", "android");
    final int selectDialogListview =
        context.getResources().getIdentifier("select_dialog_listview", "id", "android");
    final int button1 = context.getResources().getIdentifier("button1", "id", "android");
    final int button2 = context.getResources().getIdentifier("button2", "id", "android");
    final int button3 = context.getResources().getIdentifier("button3", "id", "android");

    // references
    // LinearLayout parentPanelView = (LinearLayout) dialog.findViewById(parentPanel);
    LinearLayout topPanelView = (LinearLayout) dialog.findViewById(topPanel);
    LinearLayout contentPanelView = (LinearLayout) dialog.findViewById(contentPanel);
    FrameLayout customPanelView = (FrameLayout) dialog.findViewById(customPanel);
    LinearLayout buttonPanelView = (LinearLayout) dialog.findViewById(buttonPanel);
    LinearLayout buttonPanelChildView = (LinearLayout) buttonPanelView.getChildAt(0);

    TextView alertTitleView = (TextView) dialog.findViewById(alertTitle);
    View titleDividerView = (View) dialog.findViewById(titleDivider);
    TextView messageView = (TextView) dialog.findViewById(message);
    ListView selectDialogListviewView = (ListView) dialog.findViewById(selectDialogListview);
    Button button1View = (Button) dialog.findViewById(button1);
    Button button2View = (Button) dialog.findViewById(button2);
    Button button3View = (Button) dialog.findViewById(button3);

    // dialog background
    if (topPanelView != null
        && contentPanelView != null
        && customPanelView != null
        && buttonPanelView != null) {
      setBackground(topPanelView, contentPanelView, customPanelView, buttonPanelView, light);
    }

    // dialog style
    if (alertTitleView != null)
      alertTitleView.setTextColor(context.getResources().getColor(resourceDialogTitleText));
    if (titleDividerView != null) {
      titleDividerView.setBackgroundColor(
          context.getResources().getColor(resourceDialogTitleDivider));
      ViewGroup.LayoutParams params = titleDividerView.getLayoutParams();
      params.height =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP, 2, context.getResources().getDisplayMetrics());
    }
    if (messageView != null)
      messageView.setTextColor(context.getResources().getColor(resourceDialogMessageText));
    if (selectDialogListviewView != null) {
      selectDialogListviewView.setSelector(resourceSelectorDialogButtonBg);
      selectDialogListviewView.setDivider(
          context.getResources().getDrawable(resourceShapeDialogDividerHorizontal));
    }
    if (button1View != null) {
      button1View.setTextColor(context.getResources().getColor(resourceDialogButtonText));
      button1View.setBackgroundResource(resourceSelectorDialogButtonBg);
      button1View.setTypeface(Typeface.DEFAULT);

      LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) button1View.getLayoutParams();
      params.setMargins(0, 0, 0, 0);
      button1View.setLayoutParams(params);
    }
    if (button2View != null) {
      button2View.setTextColor(context.getResources().getColor(resourceDialogButtonText));
      button2View.setBackgroundResource(resourceSelectorDialogButtonBg);
      button2View.setTypeface(Typeface.DEFAULT);

      LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) button2View.getLayoutParams();
      params.setMargins(0, 0, 0, 0);
      button2View.setLayoutParams(params);
    }
    if (button3View != null) {
      button3View.setTextColor(context.getResources().getColor(resourceDialogButtonText));
      button3View.setBackgroundResource(resourceSelectorDialogButtonBg);
      button3View.setTypeface(Typeface.DEFAULT);

      LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) button3View.getLayoutParams();
      params.setMargins(0, 0, 0, 0);
      button3View.setLayoutParams(params);
    }
    if (buttonPanelView != null) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        buttonPanelView.setShowDividers(LinearLayout.SHOW_DIVIDER_BEGINNING);
        buttonPanelView.setDividerDrawable(
            context.getResources().getDrawable(resourceShapeDialogDividerHorizontal));
      }
    }
    if (buttonPanelChildView != null) {
      buttonPanelChildView.setPadding(0, 0, 0, 0);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        buttonPanelChildView.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        buttonPanelChildView.setDividerDrawable(
            context.getResources().getDrawable(resourceShapeDialogDividerVertical));
      }
    }
  }