Commit 9a6bc052 authored by Amit Kumar's avatar Amit Kumar
Browse files

tag point with some fixes

parent c79a932c
......@@ -40,7 +40,8 @@ public class LauncherPresenter extends MvpPresenter<LauncherContract.View> imple
public void loadApps(Context context) {
checkViewAttached();
mCompositeDisposable.add(loadAppsAndIconCache(context).subscribeOn(Schedulers.io())
mCompositeDisposable.add(loadAppsAndIconCache(context)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableObserver<AllAppsList>() {
@Override
......
......@@ -30,9 +30,6 @@ public class DotRenderer {
}
public void drawDot(Canvas canvas, Rect iconBounds) {
Log.d(TAG, "drawDot() called with: canvas = [" + canvas + "], iconBounds = [" + iconBounds
+ "]");
Bitmap myBitmap = BitmapFactory.decodeResource(
mContext.getResources(),
R.drawable.notification_icon_72);
......
package org.indin.blisslaunchero.features.suggestions;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.indin.blisslaunchero.R;
import org.indin.blisslaunchero.features.launcher.LauncherActivity;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class AutoCompleteAdapter extends
RecyclerView.Adapter<AutoCompleteAdapter.AutoCompleteViewHolder> {
private List<String> mItems = new ArrayList<>();
private final Context mContext;
private final OnSuggestionClickListener mOnSuggestionClickListener;
private final LayoutInflater mInflater;
private String mQueryText;
private static final String TAG = "AutoCompleteAdapter";
public AutoCompleteAdapter(Context context) {
super();
mContext = context;
mOnSuggestionClickListener = (LauncherActivity) mContext;
mInflater = LayoutInflater.from(mContext);
}
@NonNull
@Override
public AutoCompleteAdapter.AutoCompleteViewHolder onCreateViewHolder(@NonNull ViewGroup parent,
int viewType) {
View view = mInflater.inflate(R.layout.item_suggestion, parent, false);
AutoCompleteViewHolder holder = new AutoCompleteViewHolder(view);
view.setOnClickListener(
v -> mOnSuggestionClickListener.onClick(mItems.get(holder.getAdapterPosition())));
return holder;
}
@Override
public void onBindViewHolder(@NonNull AutoCompleteAdapter.AutoCompleteViewHolder holder,
int position) {
String suggestion = mItems.get(position);
if (mQueryText != null) {
SpannableStringBuilder spannable = new SpannableStringBuilder(suggestion);
String lcSuggestion = suggestion.toLowerCase(Locale.getDefault());
int queryTextPos = lcSuggestion.indexOf(mQueryText);
while (queryTextPos >= 0) {
spannable.setSpan(new StyleSpan(Typeface.BOLD),
queryTextPos, queryTextPos + mQueryText.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new ForegroundColorSpan(Color.WHITE), queryTextPos,
queryTextPos + mQueryText.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
queryTextPos = lcSuggestion.indexOf(mQueryText, queryTextPos + mQueryText.length());
}
holder.mSuggestionTextView.setText(spannable);
} else {
holder.mSuggestionTextView.setText(suggestion);
}
}
@Override
public int getItemCount() {
return mItems.size();
}
public void updateSuggestions(List<String> suggestions, String queryText) {
mItems = suggestions;
mQueryText = queryText;
notifyDataSetChanged();
}
public void clearSuggestions() {
mItems.clear();
notifyDataSetChanged();
}
static class AutoCompleteViewHolder extends RecyclerView.ViewHolder {
private TextView mSuggestionTextView;
public AutoCompleteViewHolder(View itemView) {
super(itemView);
mSuggestionTextView = itemView.findViewById(R.id.suggestionTextView);
}
}
public interface OnSuggestionClickListener {
void onClick(String suggestion);
}
}
package org.indin.blisslaunchero.features.suggestions;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface AutoCompleteService {
@GET("/ac/")
Observable<List<AutoCompleteServiceRawResult>> query(@Query("q") String query);
}
package org.indin.blisslaunchero.features.suggestions;
public class AutoCompleteServiceRawResult {
private String phrase;
public AutoCompleteServiceRawResult(String phrase){
this.phrase = phrase;
}
public void setPhrase(String phrase) {
phrase = phrase;
}
public String getPhrase() {
return phrase;
}
}
package org.indin.blisslaunchero.features.suggestions;
import java.util.List;
public class AutoCompleteServiceResult {
public List<AutoCompleteServiceRawResult> items;
public String queryText;
public AutoCompleteServiceResult(
List<AutoCompleteServiceRawResult> items, String queryText) {
this.items = items;
this.queryText = queryText;
}
}
package org.indin.blisslaunchero.features.usagestats;
import static android.app.usage.UsageStatsManager.INTERVAL_BEST;
import android.app.usage.UsageStats;
import android.app.usage.UsageStatsManager;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.util.ArrayMap;
import android.util.Log;
import android.widget.Toast;
import org.indin.blisslaunchero.R;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class AppUsageStats {
private final Context mContext;
private final UsageStatsManager mUsageStatsManager;
private static final String TAG = "AppUsageStats";
public AppUsageStats(Context context) {
this.mContext = context;
mUsageStatsManager = (UsageStatsManager) context.getSystemService(
Context.USAGE_STATS_SERVICE);
}
public List<UsageStats> getUsageStats() {
List<UsageStats> usageStats = new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, -1);
List<UsageStats> stats = mUsageStatsManager.queryUsageStats(INTERVAL_BEST,
cal.getTimeInMillis(), System.currentTimeMillis());
Map<String, UsageStats> aggregatedStats = new HashMap<>();
final int statCount = stats.size();
for (int i = 0; i < statCount; i++) {
UsageStats newStat = stats.get(i);
UsageStats existingStat = aggregatedStats.get(newStat.getPackageName());
if (existingStat == null) {
aggregatedStats.put(newStat.getPackageName(), newStat);
} else {
existingStat.add(newStat);
}
}
if (aggregatedStats.size() == 0) {
Log.i(TAG, "The user may not allow the access to apps usage. ");
Toast.makeText(mContext,
mContext.getString(R.string.explanation_access_to_appusage_is_not_enabled),
Toast.LENGTH_LONG).show();
mContext.startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS));
Log.i(TAG, "getUsageStats: here");
} else {
Set<Map.Entry<String, UsageStats>> set = aggregatedStats.entrySet();
List<Map.Entry<String, UsageStats>> list = new ArrayList<>(set);
Collections.sort(list,
(o1, o2) -> Long.compare(o2.getValue().getTotalTimeInForeground(),
o1.getValue().getTotalTimeInForeground()));
for (Map.Entry<String, UsageStats> stringUsageStatsEntry : list) {
usageStats.add(stringUsageStatsEntry.getValue());
}
}
Log.i(TAG, "getUsageStats: here2");
return usageStats;
}
/**
* The {@link Comparator} to sort a collection of {@link UsageStats} sorted by the timestamp
* last time the app was used in the descendant order.
*/
private static class ForegroundTimeComparatorDesc implements Comparator<String> {
private Map<String, UsageStats> mMap;
public ForegroundTimeComparatorDesc(Map<String, UsageStats> map) {
this.mMap = map;
}
@Override
public int compare(String left, String right) {
return Long.compare(mMap.get(right).getTotalTimeInForeground(),
mMap.get(left).getTotalTimeInForeground());
}
}
}
File mode changed from 100644 to 100755
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