Skip to content

Commit

Permalink
Merge pull request #6 from orhanobut/oo/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
orhanobut committed Jun 7, 2015
2 parents 17c3e79 + 82ad728 commit 3c2913d
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 133 deletions.
28 changes: 8 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Bee is a QA/Debug tool that works like a widget in any application. The idea is
- Configure the application on the fly
- Add button, spinner and checkbox options regarding to your needs
- Show the predefined information such as version number, android version, package name. Add some other custom information such as current end point
- Show some usefull information to remind the user such as username, passwords for test
- Show the log for the important events, ie: An event is triggered and you want to see whether it is triggered or not

#### What Bee is not?
Expand All @@ -21,7 +20,6 @@ Bee is a QA/Debug tool that works like a widget in any application. The idea is
<img src='https://github.com/nr4bt/bee/blob/master/images/bee3.png' width='140' height='200'></img>
<img src='https://github.com/nr4bt/bee/blob/master/images/bee1.png' width='140' height='200'></img>
<img src='https://github.com/nr4bt/bee/blob/master/images/bee2.png' width='140' height='200'></img>
<img src='https://github.com/nr4bt/bee/blob/master/images/bee4.png' width='140' height='200'></img>

#### Gradle

Expand All @@ -42,24 +40,6 @@ public class SampleBeeConfig extends BeeConfig {
content.put("Current End Point", "http://www.google.com");
}

/**
* Add information to the clipboard by using content object.
*/
@Override
public void onClipboardContentCreated(Map<String, String> content) {
content.put("User1", "324234234");
content.put("Visa Expire Date", "2/16");
content.put("Visa Code", "34");
}

/**
* It is called when the save button is pressed
*/
@Override
public void onSave() {
super.onSave();
}

/**
* It is called when the close button is pressed
*/
Expand Down Expand Up @@ -95,6 +75,14 @@ public class SampleBeeConfig extends BeeConfig {
Log.d(TAG, "onEndPointSelected");
}

/**
* Change the bee button position
*/
@Override
public int getBeePosition() {
return Gravity.LEFT | Gravity.CENTER_VERTICAL;
}

}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.orhanobut.android.beesample;

import android.util.Log;
import android.view.Gravity;

import com.orhanobut.bee.BeeConfig;
import com.orhanobut.bee.widgets.Button;
Expand All @@ -17,22 +18,18 @@ public class AppBeeConfig extends BeeConfig {

private static final String TAG = AppBeeConfig.class.getSimpleName();

/**
* Add extra information by using content object.
*/

@Override
public void onInfoContentCreated(Map<String, String> content) {
content.put("Current End Point", "http://www.google.com");
public int getBeePosition() {
return Gravity.LEFT | Gravity.CENTER_VERTICAL;
}

/**
* Add information to the clipboard by using content object.
* Add extra information by using content object.
*/
@Override
public void onClipboardContentCreated(Map<String, String> content) {
content.put("User1", "324234234");
content.put("Visa Expire Date", "2/16");
content.put("Visa Code", "34");
public void onInfoContentCreated(Map<String, String> content) {
content.put("Current End Point", "http://www.google.com");
}

/**
Expand Down
4 changes: 3 additions & 1 deletion bee/src/main/java/com/orhanobut/bee/Bee.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public static void inject(Context context, Class<?> clazz) {

try {
new BeeHandler(context, clazz);
} catch (IllegalAccessException | InstantiationException e) {
} catch (IllegalAccessException e) {
Log.d(TAG, e.getMessage());
} catch (InstantiationException e) {
Log.d(TAG, e.getMessage());
}
}
Expand Down
11 changes: 6 additions & 5 deletions bee/src/main/java/com/orhanobut/bee/BeeConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.orhanobut.bee;

import android.content.Context;
import android.view.Gravity;

import java.util.List;
import java.util.Map;
Expand All @@ -14,6 +15,11 @@ public abstract class BeeConfig implements ConfigListener {

private Context context;

@Override
public int getBeePosition() {
return Gravity.CENTER_VERTICAL | Gravity.END;
}

@Override
public void setContext(Context context) {
this.context = context;
Expand Down Expand Up @@ -43,9 +49,4 @@ public void onLogContentCreated(List<String> logList) {

}

@Override
public void onClipboardContentCreated(Map<String, String> content) {

}

}
5 changes: 2 additions & 3 deletions bee/src/main/java/com/orhanobut/bee/ConfigListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
*/
interface ConfigListener {

int getBeePosition();

@SuppressWarnings("unused")
void onInfoContentCreated(Map<String, String> content);

@SuppressWarnings("unused")
void onLogContentCreated(List<String> list);

@SuppressWarnings("unused")
void onClipboardContentCreated(Map<String, String> content);

@SuppressWarnings("unused")
void onClose();

Expand Down
14 changes: 7 additions & 7 deletions bee/src/main/java/com/orhanobut/bee/SettingsAdapter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.orhanobut.bee;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -13,7 +14,6 @@
import android.widget.Spinner;
import android.widget.TextView;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

Expand Down Expand Up @@ -93,8 +93,8 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long

try {
method.invoke(instance, value);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
} catch (Exception e) {
Log.e("Bee", e.getMessage());
}

PrefHelper.setInt(context, method.getName(), position);
Expand Down Expand Up @@ -122,8 +122,8 @@ private View createButton(ViewGroup parent, MethodInfo methodInfo) {
public void onClick(View v) {
try {
method.invoke(instance);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
} catch (Exception e) {
Log.e("Bee", e.getMessage());
}
}
});
Expand All @@ -144,8 +144,8 @@ private View createCheckBox(ViewGroup parent, MethodInfo methodInfo) {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
try {
method.invoke(instance, isChecked);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
} catch (Exception e) {
Log.e("Bee", e.getMessage());
}

PrefHelper.setBoolean(context, method.getName(), isChecked);
Expand Down
58 changes: 25 additions & 33 deletions bee/src/main/java/com/orhanobut/bee/UiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.graphics.PointF;
import android.os.Build;
import android.text.ClipboardManager;
import android.util.Log;
import android.view.Display;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.LayoutInflater;
Expand All @@ -33,6 +36,7 @@
final class UiHandler implements View.OnClickListener {

private static final String TAG = UiHandler.class.getSimpleName();
private static final int BEE_SIZE = 80;

/**
* Stores all settings views
Expand Down Expand Up @@ -61,7 +65,9 @@ final class UiHandler implements View.OnClickListener {

private final ConfigListener configListener;

UiHandler(Context context, List<MethodInfo> list, ConfigListener listener) {
private final Point displaySize;

public UiHandler(Context context, List<MethodInfo> list, ConfigListener listener) {
this.context = context;
this.methodInfoList = list;
this.configListener = listener;
Expand All @@ -74,6 +80,11 @@ final class UiHandler implements View.OnClickListener {
listView = (ListView) mainContainer.findViewById(R.id.list);
beeImageView = new ImageView(context);
initListView(listView);

//calculate the display size
Display display = activity.getWindowManager().getDefaultDisplay();
displaySize = new Point();
displaySize.set(display.getWidth(), display.getHeight());
}

private void initListView(ListView listView) {
Expand Down Expand Up @@ -105,19 +116,6 @@ void initSettingsContent(List<MethodInfo> list) {
listView.setAdapter(adapter);
}

@SuppressWarnings("deprecated")
private void initClipboardContent() {
final Map<String, String> content = new LinkedHashMap<>();
configListener.onClipboardContentCreated(content);

List<ContentHolder> list = new ArrayList<>(content.size());
for (Map.Entry<String, String> entry : content.entrySet()) {
list.add(new ContentItem(entry.getKey(), entry.getValue()));
}
ContentAdapter adapter = new ContentAdapter(context, list);
listView.setAdapter(adapter);
}

private void showToast(String message) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
Expand Down Expand Up @@ -175,20 +173,14 @@ private Map<String, String> createInfoContent() {
*/
private void initListeners(View view) {
view.findViewById(R.id.close).setOnClickListener(this);
view.findViewById(R.id.save).setOnClickListener(this);
view.findViewById(R.id.settings).setOnClickListener(this);
view.findViewById(R.id.info).setOnClickListener(this);
view.findViewById(R.id.log).setOnClickListener(this);
view.findViewById(R.id.clipboard).setOnClickListener(this);
}

@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.save) {
configListener.onSave();
return;
}
if (id == R.id.close) {
mainContainer.setVisibility(View.GONE);
beeImageView.setVisibility(View.VISIBLE);
Expand All @@ -205,19 +197,13 @@ public void onClick(View v) {
}
if (id == R.id.log) {
initLogContent();
return;
}
if (id == R.id.clipboard) {
initClipboardContent();
}
}

private void setBeeButton(ViewGroup rootView) {
beeImageView.setImageResource(R.drawable.bee);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_VERTICAL | Gravity.END
BEE_SIZE, BEE_SIZE, configListener.getBeePosition()
);
beeImageView.setLayoutParams(params);
beeImageView.setOnClickListener(null);
Expand All @@ -228,13 +214,12 @@ private void setBeeButton(ViewGroup rootView) {

private final View.OnTouchListener onTouchListener = new View.OnTouchListener() {

private static final int MIN_MOVEMENT = 10;
private static final int MIN_MOVEMENT = 20;

final BeeGestureListener gestureListener = new BeeGestureListener();
final GestureDetector gestureDetector = new GestureDetector(context, gestureListener);

int prevX;
int prevY;
PointF touchPos = new PointF();

@Override
public boolean onTouch(View v, MotionEvent event) {
Expand All @@ -243,8 +228,7 @@ public boolean onTouch(View v, MotionEvent event) {
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
prevX = (int) event.getRawX();
prevY = (int) event.getRawY();
touchPos.set(event.getX(), event.getY());
break;
case MotionEvent.ACTION_MOVE:
int x = (int) event.getRawX();
Expand All @@ -253,6 +237,9 @@ public boolean onTouch(View v, MotionEvent event) {
if (!isMoveable(x, y)) {
return true;
}
if (!isInBoundaries(x, y)) {
return true;
}

FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) v.getLayoutParams();
params.topMargin = y - v.getHeight() / 2;
Expand All @@ -265,7 +252,12 @@ public boolean onTouch(View v, MotionEvent event) {
}

private boolean isMoveable(int x, int y) {
return (Math.abs(x - prevX) > MIN_MOVEMENT || Math.abs(y - prevY) > MIN_MOVEMENT);
return (Math.abs(x - touchPos.x) > MIN_MOVEMENT || Math.abs(y - touchPos.y) > MIN_MOVEMENT);
}

private boolean isInBoundaries(int x, int y) {
int half = BEE_SIZE / 2;
return !(x + half > displaySize.x || x < half || y + half > displaySize.y || y < half + 50);
}

};
Expand Down
Binary file removed bee/src/main/res/drawable-hdpi/bee.png
Binary file not shown.
Binary file removed bee/src/main/res/drawable-xhdpi/bee.png
Binary file not shown.
Binary file modified bee/src/main/res/drawable-xxhdpi/bee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bee/src/main/res/drawable-xxhdpi/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified bee/src/main/res/drawable-xxhdpi/info.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3c2913d

Please sign in to comment.