Skip to content

Commit

Permalink
Integrate an icon with MultiTaskView to show BatteryGure Ad
Browse files Browse the repository at this point in the history
Signed-off-by: sunilpaulmathew <[email protected]>
  • Loading branch information
sunilpaulmathew committed Sep 5, 2021
1 parent 4727447 commit 69f5b00
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.smartpack.kernelmanager.fragments.statistics;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -91,6 +92,7 @@ protected void addItems(List<RecyclerViewItem> items) {
statsInit(items);
}

@SuppressLint("UseCompatLoadingForDrawables")
private void statsInit(List<RecyclerViewItem> items) {
CardView cardView = new CardView(getActivity());
cardView.setDrawable(ViewUtils.getColoredIcon(R.drawable.ic_chart, requireContext()));
Expand Down Expand Up @@ -159,6 +161,15 @@ private void statsInit(List<RecyclerViewItem> items) {
mBatteryInfo.setStatsTwo(getString(R.string.capacity) + ": " + Battery.getInstance(requireActivity())
.getCapacity() + getString(R.string.mah));
}
if (Utils.isPackageInstalled("com.paget96.batteryguru", requireActivity())) {
mBatteryInfo.setIcon(getResources().getDrawable(R.drawable.ic_batteryguru));
mBatteryInfo.setOnItemClickListener(v -> {
Intent launchIntent = requireActivity().getPackageManager().getLaunchIntentForPackage("com.paget96.batteryguru");
if (launchIntent != null) {
startActivity(launchIntent);
}
});
}
battery.addItem(mBatteryInfo);
items.add(battery);
}
Expand Down Expand Up @@ -263,7 +274,7 @@ protected void refresh() {
}
}

private BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
private final BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mBatteryRaw = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0) / 10D;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,30 @@

package com.smartpack.kernelmanager.views.recyclerview;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.LinearLayout;

import androidx.appcompat.widget.AppCompatImageButton;

import com.google.android.material.progressindicator.CircularProgressIndicator;
import com.google.android.material.textview.MaterialTextView;
import com.smartpack.kernelmanager.R;
import com.smartpack.kernelmanager.utils.Utils;

/**
* Created by sunilpaulmathew <[email protected]> on December 03, 2019
*
* Largely based on the original implementation of StatsView by Willi Ye
*/
public class MultiStatsView extends RecyclerViewItem {

private AppCompatImageButton mIcon;
private CharSequence mTitle, mProgressTitle, mStatOne, mStatTwo, mStatThree;
private MaterialTextView mTitleView, mProgressTitleView, mStatViewOne, mStatViewTwo, mStatViewThree;
private CircularProgressIndicator mProgressBar;
private Drawable mDrawable;
private int mMax, mProgressPercent;
private LinearLayout mProgressLayout;
private MaterialTextView mTitleView, mProgressTitleView, mStatViewOne, mStatViewTwo, mStatViewThree;

@Override
public int getLayoutRes() {
Expand All @@ -56,6 +60,7 @@ public void onCreateView(View view) {
mProgressTitleView = view.findViewById(R.id.progress_title);
mProgressBar = view.findViewById(R.id.progress);
mProgressLayout = view.findViewById(R.id.progress_layout);
mIcon = view.findViewById(R.id.icon);
LinearLayout mParentLayout = view.findViewById(R.id.parent_layout);

if (Utils.getScreenDPI(view.getContext()) < 390 || Utils.isTablet(view.getContext()) &&
Expand Down Expand Up @@ -101,6 +106,11 @@ public void setProgressTitle(CharSequence text) {
refresh();
}

public void setIcon(Drawable icon) {
mDrawable = icon;
refresh();
}

@Override
protected void refresh() {
super.refresh();
Expand Down Expand Up @@ -133,5 +143,14 @@ protected void refresh() {
mProgressTitleView.setText(mProgressTitle);
mProgressTitleView.setVisibility(View.VISIBLE);
}
if (mIcon != null && mDrawable != null) {
mIcon.setImageDrawable(mDrawable);
mIcon.setVisibility(View.VISIBLE);
mIcon.setOnClickListener(v -> {
if (getOnItemClickListener() != null) {
getOnItemClickListener().onClick(MultiStatsView.this);
}
});
}
}
}
18 changes: 14 additions & 4 deletions app/src/main/res/layout/rv_multistats_view.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/parent_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
android:id="@+id/parent_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
android:padding="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:padding="10dp" >

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:background="@null"
android:visibility="gone" />

<LinearLayout
android:layout_width="wrap_content"
Expand Down

0 comments on commit 69f5b00

Please sign in to comment.