Commit 4dc01d3c authored by Amit Kumar's avatar Amit Kumar
Browse files

Add dynamic calendar icon

parent 6e517f7f
......@@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.List;
public class AppItem {
private CharSequence label;
private String packageName;
private Drawable icon;
......@@ -15,6 +16,7 @@ public class AppItem {
private boolean iconFromIconPack;
private boolean isSystemApp;
private boolean isClock;
private boolean isCalendar;
// Folder specific
private boolean belongsToFolder;
......@@ -25,7 +27,7 @@ public class AppItem {
public AppItem(CharSequence label, String packageName, Drawable icon,
Intent intent, String componentName, boolean iconFromIconPack, boolean isSystemApp,
boolean isClock) {
boolean isClock, boolean isCalendar) {
this.label = label;
this.packageName = packageName;
this.icon = icon;
......@@ -34,6 +36,7 @@ public class AppItem {
this.iconFromIconPack = iconFromIconPack;
this.isSystemApp = isSystemApp;
this.isClock = isClock;
this.isCalendar = isCalendar;
}
public CharSequence getLabel() {
......@@ -64,6 +67,10 @@ public class AppItem {
return isClock;
}
public boolean isCalendar() {
return isCalendar;
}
public void setSystemApp(boolean isSystemApp) {
this.isSystemApp = isSystemApp;
}
......
......@@ -4,6 +4,8 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.LayoutTransition;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.WallpaperManager;
import android.content.BroadcastReceiver;
import android.content.Context;
......@@ -21,6 +23,8 @@ import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.DragEvent;
import android.view.Gravity;
......@@ -46,9 +50,9 @@ import org.indin.blisslaunchero.R;
import org.indin.blisslaunchero.db.Storage;
import org.indin.blisslaunchero.model.AppItem;
import org.indin.blisslaunchero.utils.AppUtil;
import org.indin.blisslaunchero.utils.ConverterUtil;
import org.indin.blisslaunchero.utils.GraphicsUtil;
import org.indin.blisslaunchero.utils.IconPackUtil;
import org.indin.blisslaunchero.utils.ConverterUtil;
import org.indin.blisslaunchero.widgets.BlissDragShadowBuilder;
import org.indin.blisslaunchero.widgets.BlissInput;
import org.indin.blisslaunchero.widgets.CustomAnalogClock;
......@@ -59,6 +63,7 @@ import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.UUID;
......@@ -126,6 +131,14 @@ public class DesktopActivity extends AppCompatActivity {
private CountDownTimer mWobblingCountDownTimer;
private long longPressedAt;
private AlarmManager alarmMgr;
private PendingIntent pendingIntent;
private TextView monthTextView;
private TextView dateTextView;
private static final String TAG = "DesktopActivity";
private BroadcastReceiver alarmReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -199,10 +212,30 @@ public class DesktopActivity extends AppCompatActivity {
recreate();
}
};
alarmReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
incrementCalendarDate();
}
};
registerReceiver(alarmReceiver, new IntentFilter("DAY_CHANGED"));
registerReceiver(installReceiver, installFilter);
registerReceiver(uninstallReceiver, uninstallFilter);
}
public void incrementCalendarDate() {
Log.d(TAG, "incrementCalendarDate() called");
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
if (monthTextView != null) {
monthTextView.setText(ConverterUtil.convertMonthToString(cal.get(Calendar.MONTH)));
}
if (dateTextView != null) {
dateTextView.setText(String.valueOf(cal.get(Calendar.DAY_OF_MONTH)));
}
}
@Override
protected void onStart() {
super.onStart();
......@@ -224,6 +257,10 @@ public class DesktopActivity extends AppCompatActivity {
super.onDestroy();
unregisterReceiver(installReceiver);
unregisterReceiver(uninstallReceiver);
if (alarmMgr != null) {
alarmMgr.cancel(pendingIntent);
}
unregisterReceiver(alarmReceiver);
}
private void addNewApp(String packageName) {
......@@ -616,7 +653,7 @@ public class DesktopActivity extends AppCompatActivity {
for (int j = 0; j < pageData.length(); j++) {
JSONObject currentItemData = pageData.getJSONObject(j);
AppItem appItem = prepareAppFromJSON(currentItemData);
if(appItem !=null) {
if (appItem != null) {
if (appItem.isFolder()) {
storedItems.addAll(appItem.getSubApps());
} else {
......@@ -740,6 +777,7 @@ public class DesktopActivity extends AppCompatActivity {
"FOLDER",
false,
true,
false,
false);
folderItem.setFolder(true);
folderItem.setFolderID(currentItemData.getString("folderID"));
......@@ -815,6 +853,35 @@ public class DesktopActivity extends AppCompatActivity {
analogClock.setVisibility(View.VISIBLE);
squareImageView.setVisibility(View.GONE);
analogClock.setAutoUpdate(true);
} else if (app.isCalendar()) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
monthTextView = v.findViewById(R.id.calendar_month_textview);
monthTextView.getLayoutParams().height = appIconWidth * 40 / 192;
monthTextView.getLayoutParams().width = appIconWidth;
int monthPx = appIconWidth * 48 / 192;
monthTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, monthPx / 2);
monthTextView.setText(ConverterUtil.convertMonthToString(calendar.get(Calendar.MONTH)));
dateTextView = v.findViewById(R.id.calendar_date_textview);
int datePx = appIconWidth * 154 / 192;
dateTextView.getLayoutParams().height = appIconWidth * 152 / 192;
dateTextView.getLayoutParams().width = appIconWidth;
dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, datePx / 2);
dateTextView.setText(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
v.findViewById(R.id.icon_calendar).setVisibility(View.VISIBLE);
squareImageView.setVisibility(View.GONE);
alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent("DAY_CHANGED");
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
Calendar alarmCal = Calendar.getInstance();
alarmCal.setTimeInMillis(System.currentTimeMillis());
alarmCal.set(Calendar.HOUR_OF_DAY, 00);
alarmMgr.setInexactRepeating(AlarmManager.RTC, alarmCal.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pendingIntent);
}
......@@ -982,7 +1049,7 @@ public class DesktopActivity extends AppCompatActivity {
/**
* Toggle the wobbling animation.
*/
private void toggleWobbleAnimation(GridLayout gridLayout, boolean shouldPlayAnimation){
private void toggleWobbleAnimation(GridLayout gridLayout, boolean shouldPlayAnimation) {
for (int i = 0; i < gridLayout.getChildCount(); i++) {
ViewGroup viewGroup = (ViewGroup) gridLayout.getChildAt(i);
if (shouldPlayAnimation) {
......@@ -1462,6 +1529,7 @@ public class DesktopActivity extends AppCompatActivity {
"FOLDER",
false,
true,
false,
false);
folder.setFolder(true);
folder.setFolderID(UUID.randomUUID().toString());
......
......@@ -40,15 +40,15 @@ public class AppUtil {
boolean iconFromIconPack = true;
Drawable appIcon = null;
boolean isClock = false;
boolean isCalendar = false;
// Load icon from icon pack if present
if (IconPackUtil.iconPackPresent) {
if (!IconPackUtil.isClock(componentName)) {
appIcon = IconPackUtil.getIconFromIconPack(context, componentName);
} else {
isClock = true;
}
isClock = IconPackUtil.isClock(componentName);
isCalendar = IconPackUtil.isCalendar(componentName);
appIcon = IconPackUtil.getIconFromIconPack(context, componentName);
}
if (appIcon == null && !isClock) {
if (appIcon == null) {
appIcon = appInfo.loadIcon(packageManager);
iconFromIconPack = false;
appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f);
......@@ -69,8 +69,8 @@ public class AppUtil {
componentName,
iconFromIconPack,
isSystemApp,
isClock
);
isClock,
isCalendar);
launchableApps.add(launchableApp);
}
}
......@@ -140,9 +140,11 @@ public class AppUtil {
boolean iconFromIconPack = true;
Drawable appIcon = null;
boolean isClock = false;
boolean isCalendar = false;
// Load icon from icon pack if present
if (IconPackUtil.iconPackPresent) {
isClock = IconPackUtil.isClock(componentName);
isCalendar = IconPackUtil.isCalendar(componentName);
appIcon = IconPackUtil.getIconFromIconPack(context, componentName);
}
if (appIcon == null) {
......@@ -159,7 +161,8 @@ public class AppUtil {
componentName,
iconFromIconPack,
(appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0,
isClock);
isClock,
isCalendar);
} else {
return null;
}
......
......@@ -5,5 +5,6 @@ package org.indin.blisslaunchero.utils;
*/
public class Constants {
public static final int DEFAULT_CLOCK_ID = 971;
public static int DEFAULT_CLOCK_ID;
public static int DEFAULT_CALENDAR_ID;
}
......@@ -3,14 +3,52 @@ package org.indin.blisslaunchero.utils;
import android.content.Context;
import android.util.DisplayMetrics;
import java.util.Calendar;
public class ConverterUtil {
public static float dp2Px(int dp, Context context){
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return dp * (metrics.densityDpi / 160f);
}
public static float dp2Px(int dp, Context context) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return dp * (metrics.densityDpi / 160f);
}
public static float px2Dp(float px, Context context) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return px / (metrics.densityDpi / 160f);
}
public static float px2sp(float px, Context context) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return px / metrics.scaledDensity;
}
public static float px2Dp(float px, Context context) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return px / (metrics.densityDpi / 160f);
}
public static String convertMonthToString(int month) {
switch (month) {
case Calendar.JANUARY:
return "JAN";
case Calendar.FEBRUARY:
return "FEB";
case Calendar.MARCH:
return "MAR";
case Calendar.APRIL:
return "APR";
case Calendar.MAY:
return "MAY";
case Calendar.JUNE:
return "JUN";
case Calendar.JULY:
return "JUL";
case Calendar.AUGUST:
return "AUG";
case Calendar.SEPTEMBER:
return "SEP";
case Calendar.OCTOBER:
return "OCT";
case Calendar.NOVEMBER:
return "NOV";
case Calendar.DECEMBER:
return "DEC";
default:
return "";
}
}
}
......@@ -56,6 +56,11 @@ public class IconPackUtil {
iconMapper.get(componentName) == Constants.DEFAULT_CLOCK_ID;
}
public static boolean isCalendar(String componentName) {
return iconMapper.get(componentName) != null &&
iconMapper.get(componentName) == Constants.DEFAULT_CALENDAR_ID;
}
public static Drawable getIconFromIconPack(Context context, String componentName) {
if (iconMapper == null) {
return null;
......@@ -91,9 +96,14 @@ public class IconPackUtil {
"component").getTextContent();
String drawableName = item.getAttributes().getNamedItem(
"drawable").getTextContent();
int drawableId = drawableName.equals("clock") ? Constants.DEFAULT_CLOCK_ID
: iconPackResources.getIdentifier(drawableName, "drawable",
ICON_PACK_PACKAGE);
int drawableId = iconPackResources.getIdentifier(drawableName, "drawable",
ICON_PACK_PACKAGE);
if (drawableName.equals("clock")) {
Constants.DEFAULT_CLOCK_ID = drawableId;
} else if (drawableName.equals("calendar")) {
Constants.DEFAULT_CALENDAR_ID = drawableId;
}
if (drawableId > 0) {
iconMapper.put(componentName, drawableId);
}
......
package org.indin.blisslaunchero.widgets;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
/**
* Created by falcon on 9/3/18.
*/
public class SquareLinearLayout extends LinearLayout {
public SquareLinearLayout(@NonNull Context context) {
super(context);
}
public SquareLinearLayout(@NonNull Context context,
@Nullable AttributeSet attrs) {
super(context, attrs);
}
public SquareLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
int height = getMeasuredHeight();
int size = width < height ? width : height;
setMeasuredDimension(size, size);
}
}
......@@ -27,10 +27,14 @@
<org.indin.blisslaunchero.widgets.CustomAnalogClock
android:id="@+id/icon_clock"
android:visibility="gone"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:layout_gravity="center"
android:visibility="gone" />
<include android:id="@+id/icon_calendar"
layout="@layout/calendar_icon"
android:visibility="gone"/>
</org.indin.blisslaunchero.widgets.SquareFrameLayout>
<TextView
......
<?xml version="1.0" encoding="utf-8"?>
<org.indin.blisslaunchero.widgets.SquareLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/calendar">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/calendar_top"
android:gravity="center"
android:textColor="#FFF"
android:textAllCaps="true"
android:id="@+id/calendar_month_textview"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/calendar_date_textview"
android:textColor="#000"
android:layout_gravity="center"/>
</org.indin.blisslaunchero.widgets.SquareLinearLayout>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment