Skip to content

Commit

Permalink
Working but buggy implementation of floating window
Browse files Browse the repository at this point in the history
  • Loading branch information
KTachibanaM committed Jun 29, 2016
1 parent cc7db5b commit 8e100af
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.support.annotation.Nullable;
import android.support.v4.view.GestureDetectorCompat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.LayoutInflater;
Expand All @@ -26,6 +30,7 @@
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import org.ktachibana.cloudemoji.R;
import org.ktachibana.cloudemoji.adapters.FavoriteListViewAdapter;
Expand All @@ -39,6 +44,7 @@

public class EmoticonHeadService extends Service {
private WindowManager windowManager;
private WindowManager.LayoutParams params;
private View rootView;

private boolean showing;
Expand Down Expand Up @@ -67,7 +73,7 @@ public void onCreate() {
showing = true;

// Window params
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
Expand All @@ -80,13 +86,6 @@ public void onCreate() {
// Add
windowManager.addView(rootView, params);

rootView.post(new Runnable() {
@Override
public void run() {

}
});

// Gesture detector for icon
final GestureDetectorCompat detector = new GestureDetectorCompat(EmoticonHeadService.this, new GestureDetector.SimpleOnGestureListener() {
private float diffX;
Expand All @@ -100,8 +99,14 @@ public boolean onDown(MotionEvent e) {
}

@Override
public void onLongPress(MotionEvent e) {
// todo: refresh
public boolean onDoubleTap(MotionEvent e) {
favorites = Favorite.listAll(Favorite.class);
adapter.clear();
for (Favorite f : favorites) {
adapter.add(f);
}
adapter.notifyDataSetChanged();
return true;
}

@Override
Expand Down Expand Up @@ -140,7 +145,10 @@ public boolean onTouch(View v, MotionEvent event) {
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CopyUtils.copyToClipboard(EmoticonHeadService.this, favorites.get(position).getEmoticon());
String emoticon = favorites.get(position).getEmoticon();
CopyUtils.copyToClipboard(EmoticonHeadService.this, emoticon);

Toast.makeText(EmoticonHeadService.this, emoticon + "\n" + getString(R.string.copied), Toast.LENGTH_SHORT).show();
}
});
}
Expand Down
25 changes: 17 additions & 8 deletions app/src/main/res/layout/view_emoticon_head.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
android:id="@+id/icon"
android:src="@drawable/ic_launcher"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/icon"
android:paddingBottom="18dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="18dp" />
</RelativeLayout>

0 comments on commit 8e100af

Please sign in to comment.