Skip to content

Commit

Permalink
#145 - Add themes to the app (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
sasfmlzr authored and Swati4star committed Sep 27, 2018
1 parent 97f23b6 commit 4ddcad9
Show file tree
Hide file tree
Showing 70 changed files with 394 additions and 247 deletions.
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:theme="@style/AppThemeWhite"
tools:ignore="GoogleAppIndexingWarning,RtlEnabled">
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
Expand All @@ -31,8 +31,7 @@
android:name=".activity.MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/swati4star/createpdf/activity/ImageEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
Expand Down Expand Up @@ -33,6 +35,8 @@
import swati4star.createpdf.interfaces.OnItemClickListner;
import swati4star.createpdf.model.BrushItem;
import swati4star.createpdf.model.FilterItem;
import swati4star.createpdf.util.Constants;
import swati4star.createpdf.util.ThemeUtils;

import static swati4star.createpdf.util.BrushUtils.getBrushItems;
import static swati4star.createpdf.util.Constants.IMAGE_EDITOR_KEY;
Expand Down Expand Up @@ -72,6 +76,10 @@ public class ImageEditor extends AppCompatActivity implements OnFilterItemClicke

@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String themeName = mSharedPreferences.getString(Constants.DEFAULT_THEME_TEXT,
Constants.DEFAULT_THEME);
ThemeUtils.setThemeApp(themeName, this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo_editor);
ButterKnife.bind(this);
Expand Down Expand Up @@ -109,7 +117,9 @@ public void onStopTrackingTouch(SeekBar seekBar) {
}
});
mPhotoEditor.setBrushDrawingMode(false);
Objects.requireNonNull(getSupportActionBar()).hide();
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
}

@OnClick(R.id.nextimageButton)
Expand Down Expand Up @@ -354,7 +364,7 @@ public void onItemClick(int position) {
mPhotoEditor.setBrushColor(getResources().getColor(color));
}

public static Intent getStartIntent(Context context, ArrayList<String> uris) {
public static Intent getStartIntent(Context context, ArrayList<String> uris) {
Intent intent = new Intent(context, ImageEditor.class);
intent.putExtra(IMAGE_EDITOR_KEY, uris);
return intent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

Expand All @@ -14,13 +16,19 @@
import butterknife.ButterKnife;
import swati4star.createpdf.R;
import swati4star.createpdf.adapter.PreviewAdapter;
import swati4star.createpdf.util.Constants;
import swati4star.createpdf.util.ThemeUtils;

import static swati4star.createpdf.util.Constants.PREVIEW_IMAGES;

public class ImagesPreviewActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String themeName = mSharedPreferences.getString(Constants.DEFAULT_THEME_TEXT,
Constants.DEFAULT_THEME);
ThemeUtils.setThemeApp(themeName, this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview_images);

Expand All @@ -33,7 +41,9 @@ protected void onCreate(Bundle savedInstanceState) {
PreviewAdapter mPreviewAdapter = new PreviewAdapter(this, mImagesArrayList);
mViewPager.setAdapter(mPreviewAdapter);
mViewPager.setPageTransformer(true, new DepthPageTransformer());
Objects.requireNonNull(getSupportActionBar()).hide();
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import swati4star.createpdf.fragment.SplitFilesFragment;
import swati4star.createpdf.fragment.TextToPdfFragment;
import swati4star.createpdf.fragment.ViewFilesFragment;
import swati4star.createpdf.util.Constants;
import swati4star.createpdf.util.FeedbackUtils;
import swati4star.createpdf.util.ThemeUtils;

import static swati4star.createpdf.util.Constants.ACTION_MERGE_PDF;
import static swati4star.createpdf.util.Constants.ACTION_SELECT_IMAGES;
Expand All @@ -55,7 +57,12 @@ public class MainActivity extends AppCompatActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String themeName = mSharedPreferences.getString(Constants.DEFAULT_THEME_TEXT,
Constants.DEFAULT_THEME);
ThemeUtils.setThemeApp(themeName, this);
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Toolbar toolbar = findViewById(R.id.toolbar);
Expand Down Expand Up @@ -87,6 +94,7 @@ protected void onCreate(Bundle savedInstanceState) {

/**
* Sets a fragment based on app shortcut selected, otherwise default
*
* @return - instance of current fragment
*/
private Fragment checkForAppShortcutClicked() {
Expand Down Expand Up @@ -131,7 +139,6 @@ private void initializeValues() {
mFeedbackUtils = new FeedbackUtils(this);
mNavigationView = findViewById(R.id.nav_view);
mNavigationView.setNavigationItemSelectedListener(this);
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
setDefaultMenuSelected(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
Expand All @@ -23,6 +25,7 @@
import swati4star.createpdf.model.PreviewImageOptionItem;
import swati4star.createpdf.util.Constants;
import swati4star.createpdf.util.ImageSortUtils;
import swati4star.createpdf.util.ThemeUtils;

import static swati4star.createpdf.util.Constants.PREVIEW_IMAGES;

Expand All @@ -38,6 +41,10 @@ public class PreviewActivity extends AppCompatActivity implements PreviewImageOp

@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String themeName = mSharedPreferences.getString(Constants.DEFAULT_THEME_TEXT,
Constants.DEFAULT_THEME);
ThemeUtils.setThemeApp(themeName, this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview);

Expand All @@ -51,7 +58,9 @@ protected void onCreate(Bundle savedInstanceState) {
mViewPager.setAdapter(mPreviewAdapter);
mViewPager.setPageTransformer(true, new DepthPageTransformer());

Objects.requireNonNull(getSupportActionBar()).hide();
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
showOptions();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.afollestad.materialdialogs.MaterialDialog;
Expand All @@ -22,6 +23,7 @@
import swati4star.createpdf.R;
import swati4star.createpdf.adapter.RearrangeImagesAdapter;
import swati4star.createpdf.util.Constants;
import swati4star.createpdf.util.ThemeUtils;

import static swati4star.createpdf.util.Constants.CHOICE_REMOVE_IMAGE;
import static swati4star.createpdf.util.Constants.PREVIEW_IMAGES;
Expand All @@ -38,9 +40,15 @@ public class RearrangeImages extends AppCompatActivity implements RearrangeImage

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String themeName = mSharedPreferences.getString(Constants.DEFAULT_THEME_TEXT,
Constants.DEFAULT_THEME);
ThemeUtils.setThemeApp(themeName, this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rearrange_images);
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
ButterKnife.bind(this);
Intent intent = getIntent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

import static swati4star.createpdf.util.Constants.DEFAULT_COMPRESSION;
import static swati4star.createpdf.util.Constants.STORAGE_LOCATION;
import static swati4star.createpdf.util.Constants.THEME_BLACK;
import static swati4star.createpdf.util.Constants.THEME_DARK;
import static swati4star.createpdf.util.Constants.THEME_WHITE;
import static swati4star.createpdf.util.DialogUtils.createCustomDialogWithoutContent;
import static swati4star.createpdf.util.SettingsOptions.ImageEnhancementOptionsUtils.getEnhancementOptions;
import static swati4star.createpdf.util.StringUtils.getDefaultStorageLocation;
Expand Down Expand Up @@ -125,6 +128,9 @@ public void onItemClick(int position) {
case 3:
changeFontFamily();
break;
case 4:
setTheme();
break;
}
}

Expand Down Expand Up @@ -219,4 +225,45 @@ public void setPageSize() {
MaterialDialog materialDialog = utils.showPageSizeDialog(R.layout.set_page_size_dialog_default, true);
materialDialog.setOnDismissListener(dialog -> showSettingsOptions());
}

/**
* To modify theme
*/
public void setTheme() {
String themeName = mSharedPreferences.getString(Constants.DEFAULT_THEME_TEXT,
Constants.DEFAULT_THEME);

MaterialDialog.Builder builder = createCustomDialogWithoutContent(mActivity,
R.string.theme_edit);
MaterialDialog materialDialog = builder.customView(R.layout.dialog_theme_default, true)
.onPositive(((dialog, which) -> {
View view = dialog.getCustomView();
RadioGroup radioGroup = view.findViewById(R.id.radio_group_themes);
int selectedId = radioGroup.getCheckedRadioButtonId();
RadioButton radioButton = view.findViewById(selectedId);
String themeName1 = radioButton.getText().toString();
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putString(Constants.DEFAULT_THEME_TEXT, themeName1);
editor.apply();
mActivity.recreate();
}))
.build();
RadioGroup radioGroup = materialDialog.getCustomView().findViewById(R.id.radio_group_themes);

int position = 0;
switch (themeName) {
case THEME_BLACK:
position = 0;
break;
case THEME_DARK:
position = 1;
break;
case THEME_WHITE:
position = 2;
break;
}
RadioButton rb = (RadioButton) radioGroup.getChildAt(position);
rb.setChecked(true);
materialDialog.show();
}
}
6 changes: 6 additions & 0 deletions app/src/main/java/swati4star/createpdf/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class Constants {
public static final String DATABASE_NAME = "ImagesToPdfDB.db";
public static final String DEFAULT_FONT_FAMILY_TEXT = "DefaultFontFamily";
public static final String DEFAULT_FONT_FAMILY = "TIMES_ROMAN";
public static final String DEFAULT_THEME_TEXT = "DefaultTheme";
public static final String DEFAULT_THEME = "White";
public static final String DEFAULT_IMAGE_BORDER_TEXT = "Image_border_text";
public static final String RESULT = "result";
public static final String DEFAULT_PAGE_SIZE_TEXT = "DefaultPageSize";
Expand Down Expand Up @@ -40,4 +42,8 @@ public class Constants {
public static final String ACTION_TEXT_TO_PDF = "android.intent.action.TEXT_TO_PDF";
public static final String ACTION_MERGE_PDF = "android.intent.action.MERGE_PDF";
public static final String OPEN_SELECT_IMAGES = "open_select_images";

public static final String THEME_WHITE = "White";
public static final String THEME_BLACK = "Black";
public static final String THEME_DARK = "Dark";
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public static ArrayList<EnhancementOptionsEntity> getEnhancementOptions(Context
String.format(context.getString(R.string.font_family_value_def),
fontFamily.name())));

options.add(new EnhancementOptionsEntity(
context.getResources().getDrawable(R.drawable.baseline_settings_brightness_24),
String.format(context.getString(R.string.theme_value_def),
sharedPreferences.getString(Constants.DEFAULT_THEME_TEXT,
Constants.DEFAULT_THEME))));

return options;
}
}
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/swati4star/createpdf/util/ThemeUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package swati4star.createpdf.util;

import android.content.Context;

import swati4star.createpdf.R;

import static swati4star.createpdf.util.Constants.THEME_BLACK;
import static swati4star.createpdf.util.Constants.THEME_DARK;
import static swati4star.createpdf.util.Constants.THEME_WHITE;

public class ThemeUtils {

public static void setThemeApp(String theme, Context context) {
switch (theme) {
case THEME_WHITE:
context.setTheme(R.style.AppThemeWhite);
break;
case THEME_BLACK:
context.setTheme(R.style.AppThemeBlack);
break;
case THEME_DARK:
context.setTheme(R.style.ActivityThemeDark);
break;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/baseline_settings_brightness_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19.01L3,19.01L3,4.99h18v14.02zM8,16h2.5l1.5,1.5 1.5,-1.5L16,16v-2.5l1.5,-1.5 -1.5,-1.5L16,8h-2.5L12,6.5 10.5,8L8,8v2.5L6.5,12 8,13.5L8,16zM12,9c1.66,0 3,1.34 3,3s-1.34,3 -3,3L12,9z"/>
</vector>
13 changes: 5 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,21 @@

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
app:titleTextColor="?attr/titleToolbarTextColor"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
android:layout_height="?android:attr/actionBarSize" />

</android.support.design.widget.AppBarLayout>

<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="56dp"
android:background="@color/mb_white" />
android:layout_marginTop="56dp"/>

</android.support.design.widget.CoordinatorLayout>

Expand All @@ -46,6 +43,6 @@
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
app:menu="@menu/activity_main_drawer"/>

</android.support.v4.widget.DrawerLayout>
Loading

0 comments on commit 4ddcad9

Please sign in to comment.