Web Development Question: Scroll List with bezel - Samsung Gear S2

Hello,
I try to create anew Web Application for the GS2 using the Tizen SDK (Version : 2.4.0_Rev5 Build id : 20151223-1448).
In the main page I create a list element, to which I then add new button elements via code.
I'm using the template TAUList. Unfortunately, the scrolling using the bezel is only scrolling through the items in the list, which are initially in the list. All later added items can be scrolled only by using the touch screen. Can someone tell me, what I'm doing wring here?
Is there something,which I have to re-init, after I have altered the list?
Thanks for any hints.
HTML:
( function () {
window.addEventListener( 'tizenhwkey', function( ev ) {
if( ev.keyName === "back" ) {
var page = document.getElementsByClassName( 'ui-page-active' )[0],
pageid = page ? page.id : "";
if( pageid === "main" ) {
try {
tizen.application.getCurrentApplication().exit();
} catch (ignore) {
}
} else {
window.history.back();
}
}
} );
} () );
var XML_ADDRESS = "them? cmd=jsonlist2 room=Wohnzimmer STATE&XHR=1",
XML_METHOD = "GET";
var devListArray;
var xmlhttp;
function getFhemData(){
var objDevs = document.getElementById('devList');
var i;
xmlhttp = new XMLHttpRequest();
xmlhttp.open(XML_METHOD, XML_ADDRESS, true);
xmlhttp.overrideMimeType("application/json");
xmlhttp.setRequestHeader("Authorization", "Basic " + btoa("xxxxx" + ":" + "xxxxxxxx"));
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
var JSONCode = JSON && JSON.parse(xmlhttp.responseText);
devListArray = JSONCode.Results;
var dli;
for (i = 0; i < devListArray.length; i++) {
dli = createDevice(devListArray[i]);
objDevs.appendChild(dli);
}
xmlhttp = null;
};
}
function createDevice(dev) {
var li = document.createElement('li');
li.setAttribute('class','li-has-toggle');
var la = document.createElement('label');
la.innerHTML =dev.Name;
var divInp = document.createElement('div');
divInp.setAttribute('class','ui-toggleswitch');
var inp = document.createElement('input');
inp.setAttribute('type','checkbox');
var state = dev.Internals;
if(state.STATE ==='on'){
inp.setAttribute('checked');
}
inp.setAttribute('class','ui-switch-input');
inp.setAttribute('value','test2');
var divInpBut = document.createElement('div');
divInpBut.setAttribute('class','ui-switch-button');
divInp.appendChild(inp);
divInp.appendChild(divInpBut);
la.appendChild(divInp);
li.appendChild(la);
return li;
}
function init() {
getFhemData();
}
window.onload = function() {
init();
};
The Page:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,user-scalable=no">
<title>Circular UI</title>
<link rel="stylesheet" href="lib/tau/wearable/theme/default/tau.min.css">
<link rel="stylesheet" media="all and (-tizen-geometric-shape: circle)" href="lib/tau/wearable/theme/default/tau.circle.min.css">
<!-- load theme file for your application -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="ui-page ui-page-active" id="main">
<header class="ui-header">
<h2 class="ui-title">TAU List</h2>
</header>
<div class="ui-content">
<ul class="ui-listview" id="devList">
<li>List1</li>
<li>List2</li>
</ul>
</div>
</div>
<script type="text/javascript" src="lib/tau/wearable/js/tau.min.js"></script>
<script type="text/javascript" src="js/circle-helper.js"></script>
<script src="app.js"></script>
<script src="lowBatteryCheck.js"></script>
</body>
</html>

hi, I have the same problem :/
did you find an soloution?

Hi,
the CircleHelper.js must be adapted. After adding new items in list, call destroy on your list in listHelper[], and then call again tau.helper.SnapListStyle.create() on the list.
I don't know if there is a cleaner why as of now.

Could the problem be "devListArray.length;" related? Limiting the new items to show up...
Not sure about this.

I just came across the same problem, solution is like @jamesst20 said destroying/re-creating the SnapListStyle items in circle-helper.js
In case anyone still looking for a solution, change circle-helper.js to
Code:
/*global tau */
/*jslint unparam: true */
(function (tau) {
var page,
list,
listHelper = [],
snapList = [],
i, len;
function createSnapListStyle(page) {
if (tau.support.shape.circle) {
list = page.querySelectorAll(".ui-listview");
if (list) {
if (page.id !== "pageMarqueeList" && page.id !== "pageTestVirtualList" && page.id !== "pageAnimation") {
len = list.length;
for (i = 0; i < len; i++) {
listHelper[i] = tau.helper.SnapListStyle.create(list[i]);
}
len = listHelper.length;
if (len) {
for (i = 0; i < len; i++) {
snapList[i] = listHelper[i].getSnapList();
}
}
}
}
}
}
function destroySnapListStyle() {
len = listHelper.length;
if (len) {
for (i = 0; i < len; i++) {
listHelper[i].destroy();
}
listHelper = [];
}
}
document.addEventListener("pagebeforeshow", function (e) {
page = e.target;
createSnapListStyle(page);
});
document.addEventListener("pagebeforehide", function (e) {
destroySnapListStyle();
});
document.addEventListener("onsnaplistitemschanged", function (e) {
destroySnapListStyle();
page = e.target;
createSnapListStyle(page);
}, false);
}(tau));
Than call
Code:
document.dispatchEvent(new CustomEvent("onsnaplistitemschanged"));
whenever your list items changed.

Related

[req] f-stop calculator

hi guys, would anyone be willing to make a simple program that would calculate f-stop difference between two exposures. basically same what happens at this website.
http://imaginatorium.org/stuff/stops.htm
i think the formula is in the source of the website.
thanks in advance, i am willing to pay for this.
thanks
edit: nevermind, i actually found a service that converts websites to apps
actually i tried the website but its sucks. it just shows me the website with their ad.
can someone please convert this code to a simple app so i can use offline.
thank you so much
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang=en>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<title>How many stops?</title>
<meta name="GENERATOR" content="Brian's Brain, ver. 49">
<meta name="description" content="Javascript utility calculates the difference in stops between two exposure settings">
<meta name="keywords" content="photography, exposure, stops, stop, calculator">
<script type="text/javascript"><!--
function badno(x) { // returns true unless a positive number
return (isNaN(x/x) || x < 0);
}
function update(form) {
var shrat, aprat, exprat; // ratios (shutter speed, aperture, exposure)
var shunset = 0; // mock Bools
var apunset = 0;
// check if shutter speeds set
if (form.sh1.value.length + form.sh2.value.length == 0)
{ shrat=1;
shunset=1;
} else {
// fiddle to read shutter speed as fraction
var fract1 = form.sh1.value.split("/", 2);
var fract2 = form.sh2.value.split("/", 2);
var num1 = fract1[0]; // numerator of first shutter speed
var den1 = (fract1.length == 1) ? 1 : fract1[1];
var num2 = fract2[0]; // numerator of second shutter speed
var den2 = (fract2.length == 1) ? 1 : fract2[1];
if(fract1.length==1 && fract2.length==1 && num1*num2>1)
alert("You are calculating with large exposure times: " + num1 + " and " + num2 +
" seconds.\nDid you mean to enter 1/" + num1 + " and 1/" + num2 + "?");
shrat = (num1/den1) / (num2/den2);
if (badno(num1) || badno(num2) || badno(den1) || badno(den2))
{ alert("Missing or invalid shutter speed setting.\nMust be a positive value in seconds - usually a fraction such as 1/250.");
return 0;
}
} // end shrat calculation
// check if aperture set
if (form.ap1.value.length + form.ap2.value.length == 0)
{ aprat=1;
apunset=1;
} else {
if (badno(form.ap1.value) || badno(form.ap2.value))
{ alert("Missing or invalid aperture setting.\nMust be an f-number - enter '8' for f/8.");
return 0;
}
aprat = form.ap2.value / form.ap1.value; // *exposure* ratio (reciprocals!)
} // end aprat calculation
exprat = shrat * aprat * aprat;
if (apunset && shunset)
{ form.reset();
return 0;
}
// ---- Calculate stops
var left, right;
if (exprat > 0.999 && exprat < 1.001) exprat=1; //fudge rounding
if (exprat > 1) // top more
{ left = Math.round(exprat * 1000) / 1000;
right = 1;
form.exp1.value = "More";
form.exp2.value = "Less";
} else if (exprat < 1) // bottom more
{ left = 1;
exprat = 1/exprat; // invert for rounding
right = Math.round(exprat * 1000) / 1000;
form.exp1.value = "Less";
form.exp2.value = "More";
} else { // same!
left=1; right=1;
form.exp1.value = "Same!";
form.exp2.value = "Same!";
}
form.ratio.value = left + ":" + right;
if (left == right)
{ form.stops.value = "";
return 0; // if same, no more to do!
}
var stops = Math.log(exprat)/Math.log(2);
if (form.precision[0].checked) // whole stops
{ stops = Math.round(stops);
form.stops.value = (stops == 0) ?
"<1/2 stop" :
stops + ((stops==1) ? " stop" : " stops");
} else if (form.precision[1].checked) // round to thirds
{ thirds = Math.round(stops * 3);
if (thirds == 0)
form.stops.value = "a smidgen";
else
{ stops = Math.floor(thirds/3);
var fraction = "";
if (thirds-stops*3) fraction = (stops>0 ? "-":"") + (thirds-stops*3) + "/3";
form.stops.value = (stops?stops:"") + fraction + ((stops<2) ? " stop" : " stops");
}
} else // round to 4 decimals
{ stops = Math.round(stops * 10000)/10000;
form.stops.value = stops.toString() + ((stops==1) ? " stop" : " stops");
}
} // end function
//--></script>
<style type="text/CSS"><!--
h2 {font-family: helvetica, arial, sans-serif; text-align: center; color: #2020a0}
h3 {font-family: helvetica, arial, sans-serif; text-align: center; color: #2020a0}
h4 {font-family: times, serif; font-style: italic; color: #2020a0}
DIV.main {margin-left: 3%; margin-right: 3%}
DIV.footer {margin-left: 3%; margin-right: 3%}
DIV.fright {float: right; text-align: right; width: 50%}
DIV.narrate { color: #606060;}
DIV.illust {text-align: center; font-size:smaller; font-family: helvetica, arial, sans-serif;}
td.marked { background-color: #d0a0d0; }
--></style>
</head>
<body background="../graphics/grey2.jpg" bgcolor="#e0e0e0">
<!-- extreme tracker -->
<script type="text/javascript"><!--
an=navigator.appName;sr='http://x3.extreme-dm.com/';srw="na";srb="na";d=document;r=41;function pr {
d.write("<img src=\""+sr+"n\/?tag=chandler&p=http%3A%2F%2Fimaginatorium.org%2Fstuff%2Fstops.htm&j=y&srw="+srw+"&srb="+srb+"&l="+escape(d.referrer)+"&rs="+r+"\" height=1 width=1 alt=\"\">");}//-->
</script><script type="text/javascript" language="javascript1.2"><!--
s=screen;srw=s.width;an!="Netscape"?srb=s.colorDepth:srb=s.pixelDepth//-->
</script><script type="text/javascript"><!--
pr()//-->
</script><noscript><img src="http://x3.extreme-dm.com/z/?tag=chandler&p=http%3A%2F%2Fimaginatorium.org%2Fstuff%2Fstops.htm&j=n" height=1 width=1 alt=""></noscript>
<!-- end extreme tracker -->
<div class=main>
<h3>How many stops?</h3>
<form method=get action="http://imaginatorium.org/c">
<table border=1 cellspacing=0 cellpadding=10 align=center><tr><td><!-- border -->
<noscript><p align=center style="color: #ff0000">Warning: the calculator won't work, because Javascript is not enabled.</p>
</noscript>
<table border=0 cellspacing=0 cellpadding=5 align=center><tr>
<td></td>
<td>Shutter speed</td>
<td>Aperture</td>
<td></td>
<td>Exposure</td>
</tr><tr>
<td><i>First setting:</i></td>
<td class=marked><input type=text name=sh1 size=8 tabindex=1></td>
<td class=marked>f / <input type=text name=ap1 size=4 tabindex=2></td>
<td rowspan=2><input type="button" onClick="update(this.form)" value="Calculate" tabindex=5>
<!--img src="chev.png" width=20 height=45 alt="->"-->
</td>
<td><input type=text name=exp1 size=6 readonly tabindex=0></td>
<td rowspan=2>By <input type=text name=stops size=14 readonly tabindex=0></td>
</tr><tr>
<td><i>Second setting:</i></td>
<td class=marked><input type=text name=sh2 size=8 tabindex=3></td>
<td class=marked>f / <input type=text name=ap2 size=4 tabindex=4></td>
<td><input type=text name=exp2 size=6 readonly tabindex=0></td>
</tr><tr>
<td><i>Example:</i></td>
<td>1/125</td>
<td>(f/) 5.6</td>
</tr><tr>
<td><input type=reset></td>
<td colspan=4>Exposure ratio upper:lower <input type=text name=ratio size=20 readonly></td>
<td><input type=radio name=precision value="whole">Whole stops<br>
<input type=radio checked name=precision value="thirds">One-third stops<br>
<input type=radio name=precision value="precise">Precise stops
</td>
</tr></table></td></tr></table><!-- border --></form>
<!-- <h4>What is this "geometric progress

[Q] Android: Why are my images coming in so blurry?

I have a Slideshow for the Home Page of my app looks sorta like the Houzz apps Home Page, were it displays a new image daily. But their is one issue I am having is that all of my images are coming in so blurry. I've checked the Resolution and it shouldn't be that blurry for no reason at all. I've tried changing setScaleType such as switching it too CENTER, CENTER_CROP, and Etc... None of those seemed to work. I have tried everything too my knowledge and now I am stuck, Below are some of my relevant source code in order too successfully help me out on this issue.
This is the Home.java this is linked/runs functions of homebck.xml:
Code:
public class Home extends Fragment {
private final int FileUpload = 100;
public static final String URL =
private Context context;
private ImageView m_imageInformation;
private ImageView m_imageSave;
private ImageView m_imageWallPaper;
private ViewPager m_viewPager;
private ImageAdapter m_imageAdapter;
private ArrayList<ImageView> m_imageViewList;
private int[] m_galleryImages = new int[]{
R.drawable.ic_share,
R.drawable.ic_share,
R.drawable.ic_share
};
public static String popup_status = "";
public static File path = new File(Environment.getExternalStorageDirectory() + "");
public static Item[] fileList;
public static String chosenFile;
public static Boolean firstLvl = true;
ListAdapter adapter;
public static ArrayList<String> str = new ArrayList<String>();
public String dbPath = "/data/data/com.Celebration/";
private AboutPopup m_aboutPopup;
private InformationPopup m_informationPopup;
public static String ss;
public static List<DBManager.ImageModel> m_images;
public ImageLoader imageLoader;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// return super.onCreateView(inflater, container, savedInstanceState);
// super.onCreateView(inflater, container, savedInstanceState);
context = getActivity();
View rootView = inflater.inflate(R.layout.homebck, container, false);
m_viewPager = (ViewPager) rootView.findViewById(R.id.view_pager);
m_imageInformation = (ImageView) rootView.findViewById(R.id.image_information);
m_imageSave = (ImageView) rootView.findViewById(R.id.image_save);
m_imageWallPaper = (ImageView) rootView.findViewById(R.id.image_wallpaper);
initView();
m_imageInformation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Globals.imageNumber = m_viewPager.getCurrentItem();
m_informationPopup.showAtLocation(m_viewPager, 0, 0);
}
});
m_imageSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadFileList();
onCreateDialog(100);
}
});
m_imageWallPaper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
//sendIntent.setAction(Intent.ACTION_CHOOSER);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "");
sendIntent.putExtra(Intent.EXTRA_EMAIL, "");
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Hello, I wanted to invite you to join this app with me! It's a guide about Celebration, FL. Come see ");
sendIntent.setType("text/plain");
//Sipdroid.this.startActivity(sendIntent);*/
context.startActivity(Intent.createChooser(sendIntent, "Tell a friend via..."));
}
});
return rootView;
}
public void initView(){
m_imageViewList = new ArrayList<ImageView>();
m_aboutPopup = new AboutPopup(getActivity());
m_informationPopup = new InformationPopup(getActivity());
Globals.m_dbMan = new DBManager(context);
m_images = Globals.m_dbMan.getImageListData();
m_imageViewList.clear();
if(m_images != null){
for (int i = m_images.size() - 1 ; i >= 0; i--) {
ImageView imageView = new ImageView(context);
setImage(imageView, i);
m_imageViewList.add(imageView);
}
}else{
ImageView imageView = new ImageView(context);
imageLoader = new ImageLoader(context);
imageLoader.DisplayImage(URL, imageView);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
m_imageViewList.add(imageView);
}
m_imageAdapter = new ImageAdapter(m_imageViewList);
m_viewPager.setAdapter(m_imageAdapter);
}
public void setImage(ImageView m_imgView, int currentIndex)
{
File imgFile = new File(m_images.get(currentIndex).imagePath);
//Uri uri = Uri.fromFile(new File(lstImage.get(currentIndex).imagePath));
Bitmap myBitmap = decodeFile(imgFile);
m_imgView.setImageBitmap(myBitmap);
m_imgView.setAdjustViewBounds(true);
m_imgView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
}
public static Bitmap decodeFile(File f){
Bitmap b = null;
int IMAGE_MAX_SIZE = 1000;
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
FileInputStream fis;
try {
fis = new FileInputStream(f);
BitmapFactory.decodeStream(fis, null, o);
try {
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int scale = 1;
if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
int maxwh = Math.max(o.outWidth,o.outHeight);
while(maxwh / scale > IMAGE_MAX_SIZE)
scale *= 2;
}
Log.d("twinklestar.containerrecog", "width: " + o.outWidth + "height: " + o.outHeight + "scale:" + scale);
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
fis = new FileInputStream(f);
b = BitmapFactory.decodeStream(fis, null, o2);
try {
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return b;
}
/* @Override
public void onClick(View v) {
Log.d("onclick", "ok");
switch (v.getId()){
case R.id.image_information:
{
Toast.makeText(context, "ok", Toast.LENGTH_SHORT).show();
break;
}
case R.id.image_save:
{
// loadFileList();
onCreateDialog(100);
break;
}
case R.id.image_wallpaper:
{
((Activity)context).finish();
break;
}
default:
break;
}
}*/
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
if (fileList == null) {
Log.e("TAG", "No files loaded");
dialog = builder.create();
return dialog;
}
switch (id) {
case FileUpload:
builder.setTitle("Select a Folder to save");
builder.setPositiveButton("download", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
ImageView image = new ImageView(context);
imageLoader = new ImageLoader(context);
Globals.downloadFlag = true;
Globals.downlaodForSaving = true;
Globals.saveFolder = path.toString();
imageLoader.DisplayImage(URL, image);
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
});
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
chosenFile = fileList[which].file;
File sel = new File(path + "/" + chosenFile);
if (sel.isDirectory()) {
firstLvl = false;
// Adds chosen directory to list
str.add(chosenFile);
fileList = null;
path = new File(sel + "");
loadFileList();
dialog.dismiss();
onCreateDialog(FileUpload);
Log.d("TAG", path.getAbsolutePath());
}
// Checks if 'up' was clicked
else if (chosenFile.equalsIgnoreCase("up") && !sel.exists()) {
// present directory removed from list
String s = str.remove(str.size() - 1);
// path modified to exclude present directory
path = new File(path.toString().substring(0,
path.toString().lastIndexOf(s)));
fileList = null;
// if there are no more directories in the list, then
// its the first level
if (str.isEmpty()) {
firstLvl = true;
}
loadFileList();
//UploadFragment.this.getActivity().removeDialog(DIALOG_LOAD_FILE);
dialog.dismiss();
onCreateDialog(FileUpload);
//UploadFragment.this.getActivity().showDialog(DIALOG_LOAD_FILE);
Log.d("TAG", path.getAbsolutePath());
}
// File picked
else {
// Perform action with file picked
//Toast.makeText(UploadFragment.this.getActivity(), chosenFile, Toast.LENGTH_SHORT).show();
ss = path.getAbsolutePath() + "/" + chosenFile;
String extension = chosenFile.substring(chosenFile.indexOf(".") + 1);
if (extension.equals("png") || extension.equals("jpg") || extension.equals("bmp")) {
dialog.dismiss();
m_aboutPopup.showAtLocation(m_viewPager, 0, 0);
// onUpload(ss,chosenFile);
} else
Toast.makeText(getActivity(), "This is not image file!", Toast.LENGTH_SHORT).show();
}
}
});
break;
}
dialog = builder.show();
return dialog;
}
Below this a SNIPPET/part of the MainActivity.java *hint URL1,2,3,4... Grabs the URL that is put into String:
Code:
public static String des;
public String myurl = null;
public class AboutPopup implements View.OnClickListener {
public View parent;
public PopupWindow popupWindow;
public ListView m_listHolder;
public EditText m_editDescription;
public Button m_btnUpload;
public DatePicker dp;
public TimePicker tp;
private PendingIntent pendingIntent;
private Spinner spinner;
private ImageView imageView;
private TextView selectImageurl;
private TextView imageDescription;
public AboutPopup(Context paramContext) {
this.parent = ((LayoutInflater) paramContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.settting_popup, null);
//this.parent.findViewBy)
this.popupWindow = new PopupWindow(this.parent, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, true);
this.m_editDescription = (EditText) parent.findViewById(R.id.setting_description);
this.m_btnUpload = (Button) parent.findViewById(R.id.btn_setting_show);
m_btnUpload.setOnClickListener(this);
selectImageurl = (TextView) parent.findViewById(R.id.select_imageurl);
imageDescription = (TextView) parent.findViewById(R.id.image_description);
selectImageurl.setTextSize(convertFromDp(24));
imageDescription.setTextSize(convertFromDp(24));
dp = (DatePicker) parent.findViewById(R.id.datePicker);
tp = (TimePicker) parent.findViewById(R.id.timePicker);
dp.setCalendarViewShown(false);
imageView = (ImageView)parent.findViewById(R.id.setting_image);
spinner = (Spinner) parent.findViewById(R.id.setting_spinner);
String[] platforms = paramContext.getResources(). getStringArray(R.array.dev_platforms);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(paramContext, R.layout.spinner_item, platforms);
spinner.setAdapter(adapter);
// If you want to continue on that TimeDateActivity
// If you want to go to new activity that code you can also write here
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position){
case 0:
myurl = URL;
break;
case 1:
myurl = URL1;
break;
case 2:
myurl = URL3;
break;
case 3:
myurl = URL4;
break;
case 4:
break;
}
if(myurl != null){
imageLoader = new ImageLoader(MainActivity.this);
imageLoader.DisplayImage(myurl, imageView);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
public void showAtLocation(View pView, int left, int top) {
this.popupWindow.setOutsideTouchable(true);
this.popupWindow.setTouchable(true);
this.popupWindow.update();
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setAnimationStyle(R.style.PopupAnimation);
popupWindow.setWidth((int) (pView.getWidth() * 0.95));
popupWindow.setHeight((int) (pView.getHeight()));
popupWindow.showAtLocation(pView, Gravity.CENTER_VERTICAL, 0, 0);
// this.popupWindow.showAtLocation(pView, Gravity.CENTER, left, top);
}
public void hide() {
this.popupWindow.dismiss();
}
public boolean isVisible() {
return this.popupWindow.isShowing();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_setting_show: {
imageLoader = new ImageLoader(MainActivity.this);
Globals.downloadFlag = true;
imageLoader.DisplayImage(myurl, imageView);
ss = path.getAbsolutePath() + "/" + ImageLoader.fname;
des = this.m_editDescription.getText().toString();
Globals.alarmFileName[Globals.alarmNumber] = ImageLoader.fname;
Globals.alarmDescription[Globals.alarmNumber] = des;
Globals.alarmNumber = Globals.alarmNumber + 1;
String strDateTime = dp.getYear() + "-" + (dp.getMonth() + 1) + "-" + dp.getDayOfMonth();
Intent Intent = new Intent(MainActivity.this, AlarmReceiver.class);
Intent.putExtra("id",Globals.alarmNumber-1);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, Intent, 0);
Calendar cal = Calendar.getInstance();
cal.set(dp.getYear(), dp.getMonth(), dp.getDayOfMonth(),tp.getCurrentHour(), tp.getCurrentMinute());
Calendar current = Calendar.getInstance();
if(current.get(Calendar.YEAR) > cal.get(Calendar.YEAR) && current.get(Calendar.MONTH) > cal.get(Calendar.MONTH) && current.get(Calendar.DATE) > cal.get(Calendar.DATE)){
Toast.makeText(MainActivity.this, "Please select other time", Toast.LENGTH_SHORT).show();
return;
}
// schedule for every 30 seconds
alarm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
if (des == null) {
Toast.makeText(MainActivity.this, "Input description in..", Toast.LENGTH_SHORT).show();
return;
} else {
popupWindow.dismiss();
}
}
break;
}
}
}
homebck.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="..."
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/homefragment"
android:background="@color/white">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1">
<ImageView
android:id="@+id/image_information"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@drawable/ic_information"
android:layout_weight="1" />
<ImageView
android:id="@+id/image_save"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@drawable/ic_save"
android:layout_weight="1"
/>
<ImageView
android:id="@+id/image_wallpaper"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@drawable/ic_share"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

One smali code but 2 different in Java source

hi everyone
i'm very noob in android because i'm a Java EE developer.
ok i have one apk file that i want to change the source code in to JAVA.
i decompiled the apk file in two ways:
first, i used apktool ,dex2jar, jd-ui and then i got this java code :
Code:
package com.sunglab.bigbanghd;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.*;
//import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageButton;
public class MainActivity
extends Activity
implements SensorEventListener
{
public static final int Amazon = 1;
public static final int Google = 0;
public static boolean IsthatPlaying = true;
public static final int Samsung = 3;
public static final int Tstore = 2;
public static MediaPlayer mPlayer;
public static int store = WallpaperSettings.store;
public int MusicNumber = 0;
Handler handler;
Intent intent;
GL2JNIView.Renderer mRenderer;
private GL2JNIView mView;
Sensor m_ot_sensor;
SensorManager m_sensor_manager;
ImageButton menu_Button;
public void abc(int paramInt)
{
switch (paramInt)
{
}
do
{
do
{
do
{
do
{
do
{
return;
Log.e("else", "Playing 0");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 2131034112);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
} while (!IsthatPlaying);
mPlayer.start();
return;
Log.e("else", "Playing 1");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 2131034113);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
} while (!IsthatPlaying);
mPlayer.start();
return;
Log.e("else", "Playing 2");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 2131034114);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
} while (!IsthatPlaying);
mPlayer.start();
return;
Log.e("else", "Playing 3");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 2131034115);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
} while (!IsthatPlaying);
mPlayer.start();
return;
Log.e("else", "Playing 4");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 2131034116);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
} while (!IsthatPlaying);
mPlayer.start();
}
public void onAccuracyChanged(Sensor paramSensor, int paramInt)
{
Log.e("Sensor working", "Good ratated2s");
}
public void onBackPressed()
{
Log.e("omg", "Back key");
AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
localBuilder.setIcon(2130837507);
if ((store == 2) || (store == 3)) {
localBuilder.setTitle("이 앱을 종료 하시겠습니까?");
}
for (;;)
{
localBuilder.setCancelable(false);
if ((store != 2) && (store != 3)) {
localBuilder.setPositiveButton("More Apps", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
switch (MainActivity.store)
{
}
for (;;)
{
MainActivity.this.startActivity(MainActivity.this.intent);
return;
MainActivity.this.intent = new Intent("android.intent.action.VIEW", Uri.parse("xxxx"));
continue;
MainActivity.this.intent = new Intent("android.intent.action.VIEW", Uri.parse("xxx"));
}
}
});
}
localBuilder.setNeutralButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
paramAnonymousDialogInterface.cancel();
}
});
localBuilder.setNegativeButton("Exit", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
MainActivity.this.finish();
}
});
localBuilder.show();
return;
localBuilder.setTitle("Do you need More SungLab Apps ?");
}
}
public void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
Log.e("gg", "onCreate");
this.m_sensor_manager = ((SensorManager)getSystemService("sensor"));
this.m_ot_sensor = this.m_sensor_manager.getDefaultSensor(3);
this.mView = new GL2JNIView(getApplication());
setContentView(this.mView);
SharedPreferences localSharedPreferences = getSharedPreferences("wallpaperSet", 0);
int i = localSharedPreferences.getInt("THICK", 5);
int j = localSharedPreferences.getInt("TAIL", 7);
int k = localSharedPreferences.getInt("NUMBER", 5999);
int m = localSharedPreferences.getInt("COLORS", 0);
if (Boolean.valueOf(localSharedPreferences.getBoolean("MUSIC", true)).booleanValue()) {}
for (IsthatPlaying = true;; IsthatPlaying = false)
{
GL2JNIView.Renderer.number = k + 1;
GL2JNIView.Renderer.tail = 0.99F - (0.2F - 0.02F * j);
GL2JNIView.Renderer.thick = 1.0F + 0.4F * i;
GL2JNIView.Renderer.colors = m;
addContentView(((LayoutInflater)getSystemService("layout_inflater")).inflate(2130903040, null), new ViewGroup.LayoutParams(-1, -1));
getWindow().setFlags(128, 128);
mPlayer = MediaPlayer.create(this, 2131034112);
if (!IsthatPlaying) {
mPlayer.pause();
}
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
if (MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
}
for (;;)
{
MainActivity localMainActivity = MainActivity.this;
localMainActivity.MusicNumber = (1 + localMainActivity.MusicNumber);
if (MainActivity.this.MusicNumber == 5) {
MainActivity.this.MusicNumber = 0;
}
MainActivity.this.abc(MainActivity.this.MusicNumber);
return;
Log.e("else", "finish");
}
}
});
this.menu_Button = ((ImageButton)findViewById(2131296256));
this.menu_Button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
MainActivity.this.startActivity(new Intent(MainActivity.this, WallpaperSettings.class));
}
});
return;
}
}
protected void onDestroy()
{
super.onDestroy();
this.mView = null;
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
mPlayer.release();
mPlayer = null;
Log.e("omg", "Destroy");
}
public void onHomePressed()
{
Log.e("omg", "Home key");
}
protected void onPause()
{
super.onPause();
this.mView.onPause();
if (IsthatPlaying) {
mPlayer.pause();
}
this.m_sensor_manager.unregisterListener(this);
Log.e("omg", "onPause");
}
protected void onResume()
{
super.onResume();
this.mView.onResume();
Log.e("omg", "onResume");
if (Boolean.valueOf(getSharedPreferences("wallpaperSet", 0).getBoolean("MUSIC", true)).booleanValue())
{
IsthatPlaying = true;
if (!IsthatPlaying) {
break label82;
}
mPlayer.start();
}
for (;;)
{
this.m_sensor_manager.registerListener(this, this.m_ot_sensor, 2);
return;
IsthatPlaying = false;
break;
label82:
mPlayer.pause();
}
}
public void onSensorChanged(SensorEvent paramSensorEvent)
{
if (paramSensorEvent.sensor.getType() == 3)
{
if ((int)paramSensorEvent.values[2] > 45) {
GL2JNIView.Renderer.DefinallyROTATION = -90;
}
}
else {
return;
}
if ((int)paramSensorEvent.values[2] < -45)
{
GL2JNIView.Renderer.DefinallyROTATION = 90;
return;
}
GL2JNIView.Renderer.DefinallyROTATION = 0;
}
public boolean onTouchEvent(MotionEvent paramMotionEvent)
{
int i = paramMotionEvent.getPointerCount();
int j = 0;
if (j >= i) {
switch (paramMotionEvent.getAction())
{
}
}
for (;;)
{
return true;
GL2JNIView.TouchMoveNumber(paramMotionEvent.getX(j), paramMotionEvent.getY(j), j, paramMotionEvent.getPointerCount());
j++;
break;
GL2JNIView.TouchUpNumber();
continue;
GL2JNIView.TouchDownNumber();
continue;
GL2JNIView.TouchDownNumber();
}
}
}
/* Location: C:\jd-gui-windows-1.4.0\classes_dex2jar.jar!\com\sunglab\bigbanghd\MainActivity.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/
and the second way i used backSmali tool and jd-ui , i got this JAVA code:
Code:
/**
* Generated by smali2java 1.0.0.558
* Copyright (C) 2013 Hensence.com
*/
package com.sunglab.bigbanghd;
import android.app.Activity;
import android.hardware.SensorEventListener;
import android.media.MediaPlayer;
import android.os.Handler;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.widget.ImageButton;
import android.util.Log;
import android.content.Context;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.app.Application;
import android.view.View;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.Window;
import android.hardware.SensorEvent;
import android.view.MotionEvent;
public class MainActivity extends Activity implements SensorEventListener {
public static final int Amazon = 0x1;
public static final int Google = 0x0;
public int MusicNumber;
public static final int Samsung = 0x3;
public static final int Tstore = 0x2;
Handler handler;
Intent intent;
public static MediaPlayer mPlayer;
GL2JNIView.Renderer mRenderer;
private GL2JNIView mView;
Sensor m_ot_sensor;
SensorManager m_sensor_manager;
ImageButton menu_Button;
public static int store = WallpaperSettings.store;
public static boolean IsthatPlaying = 0x1;
public void onCreate(Bundle p1) {
super.onCreate(p1);
Log.e("gg", "onCreate");
m_sensor_manager = (SensorManager)getSystemService("sensor");
m_ot_sensor = m_sensor_manager.getDefaultSensor(0x3);
mView = new GL2JNIView(getApplication());
setContentView(mView);
SharedPreferences "preferences" = getSharedPreferences("wallpaperSet", 0x0);
int "thickness" = "preferences".getInt("THICK", 0x5);
int "tails" = "preferences".getInt("TAIL", 0x7);
int "particleNumber" = "preferences".getInt("NUMBER", 0x176f);
int "colors" = "preferences".getInt("COLORS", 0x0);
Boolean "music" = Boolean.valueOf("preferences".getBoolean("MUSIC", true));
if("music".booleanValue()) {
IsthatPlaying = 0x1;
} else {
IsthatPlaying = 0x0;
}
GL2JNIView.Renderer.number = ("particleNumber" + 0x1);
GL2JNIView.Renderer.tail = (0x3f7d70a4 # 0.99f - (0x3e4ccccd # 0.2f - ((float)"tails" * 0x3ca3d70a # 0.02f)));
GL2JNIView.Renderer.thick = (0.0f + ((float)"thickness" * 0x3ecccccd # 0.4f));
GL2JNIView.Renderer.colors = "colors";
LayoutInflater "vi" = (LayoutInflater)getSystemService("layout_inflater");
View "v" = "vi".inflate(0x0, 0x0);
addContentView("v", new ViewGroup.LayoutParams(-0x1, -0x1));
getWindow().setFlags(0x80, 0x80);
mPlayer = MediaPlayer.create(this, 0x0);
if(!IsthatPlaying) {
mPlayer.pause();
}
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {
1(MainActivity p1) {
}
public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
menu_Button = (ImageButton)findViewById(0x0);
menu_Button.setOnClickListener(new View.OnClickListener(this) {
2(MainActivity p1) {
}
public void onClick(View p1) {
startActivity(new Intent(this$0, WallpaperSettings.class));
}
});
}
public void abc(int p1) {
switch(p1) {
case 0:
{
Log.e("else", "Playing 0");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 0x0);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {
3(MainActivity p1) {
}
public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
if(IsthatPlaying) {
mPlayer.start();
}
return;
}
case 1:
{
Log.e("else", "Playing 1");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 0x7f050001);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {
4(MainActivity p1) {
}
public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
if(IsthatPlaying) {
mPlayer.start();
}
return;
}
case 2:
{
Log.e("else", "Playing 2");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 0x7f050002);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {
5(MainActivity p1) {
}
public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
if(IsthatPlaying) {
mPlayer.start();
}
return;
}
case 3:
{
Log.e("else", "Playing 3");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 0x7f050003);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {
6(MainActivity p1) {
}
public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
if(IsthatPlaying) {
mPlayer.start();
}
return;
}
case 4:
{
Log.e("else", "Playing 4");
mPlayer.reset();
mPlayer = MediaPlayer.create(this, 0x7f050004);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(this) {
7(MainActivity p1) {
}
public void onCompletion(MediaPlayer p1) {
if(MainActivity.mPlayer.isPlaying()) {
Log.e("else", "finish but playing");
} else {
Log.e("else", "finish");
}
MusicNumber = (MusicNumber + 0x1);
if(MusicNumber == 0x5) {
MusicNumber = 0x0;
}
abc(MusicNumber);
}
});
if(IsthatPlaying) {
mPlayer.start();
break;
}
}
}
}
protected void onPause() {
super.onPause();
mView.onPause();
if(IsthatPlaying) {
mPlayer.pause();
}
m_sensor_manager.unregisterListener(this);
Log.e("omg", "onPause");
}
protected void onResume() {
super.onResume();
mView.onResume();
Log.e("omg", "onResume");
SharedPreferences "preferences" = getSharedPreferences("wallpaperSet", 0x0);
Boolean "music" = Boolean.valueOf("preferences".getBoolean("MUSIC", true));
if("music".booleanValue()) {
IsthatPlaying = 0x1;
} else {
IsthatPlaying = 0x0;
}
if(IsthatPlaying) {
mPlayer.start();
} else {
mPlayer.pause();
}
m_sensor_manager.registerListener(this, m_ot_sensor, 0x2);
}
public void onSensorChanged(SensorEvent p1) {
if(p1.sensor.getType() == 0x3) {
if((int)p1.values[0x2] > 0x2d) {
GL2JNIView.Renderer.DefinallyROTATION = -0x5a;
return;
}
if((int)p1.values[0x2] < -0x2d) {
GL2JNIView.Renderer.DefinallyROTATION = 0x5a;
return;
}
GL2JNIView.Renderer.DefinallyROTATION = 0x0;
}
}
public void onAccuracyChanged(Sensor p1, int p2) {
Log.e("Sensor working", "Good ratated2s");
}
protected void onDestroy() {
super.onDestroy();
mView = 0x0;
if(mPlayer.isPlaying()) {
mPlayer.stop();
}
mPlayer.release();
mPlayer = 0x0;
Log.e("omg", "Destroy");
}
public void onBackPressed() {
Log.e("omg", "Back key");
AlertDialog.Builder "d" = new AlertDialog.Builder(this);
"d".setIcon(0x7f020003);
if((store == 0x2) || (store == 0x3)) {
"d".setTitle("\uc774 \uc571\uc744 \uc885\ub8cc \ud558\uc2dc\uaca0\uc2b5\ub2c8\uae4c?");
} else {
"d".setTitle("Do you need More SungLab Apps ?");
}
"d".setCancelable(false);
if((store != 0x2) && (store != 0x3)) {
"d".setPositiveButton("More Apps", new DialogInterface.OnClickListener(this) {
8(MainActivity p1) {
}
public void onClick(DialogInterface p1, int p2) {
switch(MainActivity.store) {
case 0:
{
new Intent("android.intent.action.VIEW", Uri.parse("xx"));
intent = localIntent1;
break;
}
case 1:
{
new Intent("android.intent.action.VIEW", Uri.parse("xxxx"));
intent = localIntent2;
break;
}
}
startActivity(intent);
}
});
}
"d".setNeutralButton("Cancel", new DialogInterface.OnClickListener(this) {
9(MainActivity p1) {
}
public void onClick(DialogInterface p1, int p2) {
p1.cancel();
}
});
"d".setNegativeButton("Exit", new DialogInterface.OnClickListener(this) {
10(MainActivity p1) {
}
public void onClick(DialogInterface p1, int p2) {
finish();
}
});
"d".show();
}
public void onHomePressed() {
Log.e("omg", "Home key");
}
public boolean onTouchEvent(MotionEvent p1) {
int "pointerCount" = p1.getPointerCount();
for(int "i" = 0x0; "i" >= "pointerCount"; "i" = "i" + 0x1) {
}
GL2JNIView.TouchMoveNumber(p1.getX("i"), p1.getY("i"), "i", p1.getPointerCount());
switch(p1.getAction()) {
case 1:
{
GL2JNIView.TouchUpNumber();
break;
}
case 0:
{
GL2JNIView.TouchDownNumber();
break;
}
case 5:
{
GL2JNIView.TouchDownNumber();
break;
}
case 2:
case 3:
case 4:
{
return true;
}
}
}
}
now i have a question why both of java codes are not the same?? for example, in the first one, we have some (do while) loops but in the second way we don't have them???
and as you can see, in the first one some lines seem wrong (in abc() method or it has written for( ;; ) ).
And also in the second one, in abc() method, we have switch case but in the first one we don't have it.
i want to edit some lines and codes but it seems the original decompiled code doesn't work.

Unable to display images in webView while epub Rendering using epublib.

Here is the code of my epub parser class.
public class EPubParser extends AppCompatActivity {
String path = null;
Book book = null;
String linez = null;
TextView textView;
private int pxScreenWidth;
int textSize = 12;
Drawable imageAsDrawable;
List<String> spineElements;
List<SpineReference> spineList;
@SuppressLint("SetJavaScriptEnabled")
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.layout_epub_render);
getSupportActionBar().setTitle("EPub Reader");
WebView webView = (WebView) findViewById(R.id.web_view);
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setJavaScriptEnabled(true);
//to get Path
Intent intent = this.getIntent();
if (intent.getAction() != null) {
path = intent.getData().getPath();
} else {
path = intent.getExtras().getString("PATH");
}
try {
File file = new File(path);
FileInputStream fileInputStream = new FileInputStream(file);
EpubReader epubReader = new EpubReader();
book = epubReader.readEpub(fileInputStream);
} catch (Exception e) {
Log.e("While loading book ", e.toString());
}
//loading the contents
Spine spine = book.getSpine();
spineList = spine.getSpineReferences();
int count = spineList.size();
//gathering all data from spine
StringBuilder string = new StringBuilder();
for (int i = 0; i < count; i++) {
Resource res = spine.getResource(i);
try {
InputStream is = res.getInputStream();
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
String line = null;
try {
while ((line = reader.readLine()) != null) {
linez = string.append(line + "\n").toString();
}
} catch (IOException e) {
e.printStackTrace();
}
//do with stream
} catch (IOException e) {
e.printStackTrace();
}
// linez = linez.replace("../", "");
webView.loadDataWithBaseURL(null, linez, "text/html", "UTF-8", null);
webView.getSettings().setBuiltInZoomControls(true);
}
}
}
Please help.

How to crop bitmaps according to size of a custom view

Trying to make a motion detection app. The intention is to make the app take pictures when motion is detected by comparing two images. Up to this part, the app is working fine.
Requirement:
To specify area of detection by a custom view. So that, the pictures will be captured only if a motion is detected inside the defined area by calculating the detection area.
What I have tried:
Created a movable custom view, like a crop view of which the dimensions (`Rect`) are saved in the preference each time when the view is moved.
In the detection thread I tried setting the width and height from the preference like
Code:
private int width = Prefe.DetectionArea.width();
private int height = Prefe.DetectionArea.height();
But it didn't work.
What is not working:
The motion detection from inside the custom view is not working. I believe that the bitmaps must be cropped according to the size of the custom view.
Please help me by explaining how this could be achieved so that the motion detection will happen according to the size of the custom view. I'm new to android and trying to self learn, any help is appreciated.
MotionDetectionActivity.java
Code:
public class MotionDetectionActivity extends SensorsActivity {
private static final String TAG = "MotionDetectionActivity";
private static long mReferenceTime = 0;
private static IMotionDetection detector = null;
public static MediaPlayer song;
public static Vibrator mVibrator;
private static SurfaceView preview = null;
private static SurfaceHolder previewHolder = null;
private static Camera camera = null;
private static boolean inPreview = false;
private static AreaDetectorView mDetector;
private static FrameLayout layoutDetectorArea;
static FrameLayout layoutMain;
static View mView;
private static volatile AtomicBoolean processing = new AtomicBoolean(false);
/**
* {@inheritDoc}
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.main);
mVibrator = (Vibrator)this.getSystemService(VIBRATOR_SERVICE);
layoutMain=(FrameLayout)findViewById(R.id.layoutMain);
preview = (SurfaceView) findViewById(R.id.preview);
previewHolder = preview.getHolder();
previewHolder.addCallback(surfaceCallback);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mView=layoutMain;
mDetector= (AreaDetectorView) findViewById(R.id.viewDetector);
layoutDetectorArea=(FrameLayout) findViewById(R.id.layoutDetectArea);
ToggleButton toggle = (ToggleButton) findViewById(R.id.simpleToggleButton);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// The toggle is enabled
} else {
// The toggle is disabled
}
}
});
if (Preferences.USE_RGB) {
detector = new RgbMotionDetection();
} else if (Preferences.USE_LUMA) {
detector = new LumaMotionDetection();
} else {
// Using State based (aggregate map)
detector = new AggregateLumaMotionDetection();
}
}
/**
* {@inheritDoc}
*/
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
/**dd:
* Song play # 1
* Camera callback
*
* {@inheritDoc}
*/
@Override
public void onPause() {
super.onPause();
if(song!=null && song.isPlaying())
{
song.stop();}
camera.setPreviewCallback(null);
if (inPreview) camera.stopPreview();
inPreview = false;
camera.release();
camera = null;
}
/**
* {@inheritDoc}
*/
@Override
public void onResume() {
super.onResume();
camera = Camera.open();
}
private PreviewCallback previewCallback = new PreviewCallback() {
/**
* {@inheritDoc}
*/
@Override
public void onPreviewFrame(byte[] data, Camera cam) {
if (data == null) return;
Camera.Size size = cam.getParameters().getPreviewSize();
if (size == null) return;
if (!GlobalData.isPhoneInMotion()) {
DetectionThread thread = new DetectionThread(data, size.width, size.height);
thread.start();
}
}
};
private SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() {
/**
* {@inheritDoc}
*/
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
camera.setPreviewDisplay(previewHolder);
camera.setPreviewCallback(previewCallback);
} catch (Throwable t) {
Log.e("Prek", "Exception in setPreviewDisplay()", t);
}
}
/**
* {@inheritDoc}
*/
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if(camera != null) {
Camera.Parameters parameters = camera.getParameters();
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
Camera.Size size = getBestPreviewSize(width, height, parameters);
if (size != null) {
parameters.setPreviewSize(size.width, size.height);
Log.d(TAG, "Using width=" + size.width + " height=" + size.height);
}
camera.setParameters(parameters);
camera.startPreview();
inPreview = true;
}
//AreaDetectorView.InitDetectionArea();
}
/**
* {@inheritDoc}
*/
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// Ignore
}
};
private static Camera.Size getBestPreviewSize(int width, int height, Camera.Parameters parameters) {
Camera.Size result = null;
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
if (size.width <= width && size.height <= height) {
if (result == null) {
result = size;
} else {
int resultArea = result.width * result.height;
int newArea = size.width * size.height;
if (newArea > resultArea) result = size;
}
}
}
return result;
}
//***************Detection Class******************//
private final class DetectionThread extends Thread {
private byte[] data;
private int width;
private int height;
public DetectionThread(byte[] data, int width, int height) {
this.data = data;
this.width = width;
this.height = height;
}
/**
* {@inheritDoc}
*/
@Override
public void run() {
if (!processing.compareAndSet(false, true)) return;
// Log.d(TAG, "BEGIN PROCESSING...");
try {
// Previous frame
int[] pre = null;
if (Preferences.SAVE_PREVIOUS) pre = detector.getPrevious();
// Current frame (with changes)
// long bConversion = System.currentTimeMillis();
int[] img = null;
if (Preferences.USE_RGB) {
img = ImageProcessing.decodeYUV420SPtoRGB(data, width, height);
} else {
img = ImageProcessing.decodeYUV420SPtoLuma(data, width, height);
}
// Current frame (without changes)
int[] org = null;
if (Preferences.SAVE_ORIGINAL && img != null) org = img.clone();
if (img != null && detector.detect(img, width, height)) {
// The delay is necessary to avoid taking a picture while in
// the
// middle of taking another. This problem can causes some
// phones
// to reboot.
long now = System.currentTimeMillis();
if (now > (mReferenceTime + Preferences.PICTURE_DELAY)) {
mReferenceTime = now;
//mVibrator.vibrate(10);
Bitmap previous = null;
if (Preferences.SAVE_PREVIOUS && pre != null) {
if (Preferences.USE_RGB) previous = ImageProcessing.rgbToBitmap(pre, width, height);
else previous = ImageProcessing.lumaToGreyscale(pre, width, height);
}
Bitmap original = null;
if (Preferences.SAVE_ORIGINAL && org != null) {
if (Preferences.USE_RGB) original = ImageProcessing.rgbToBitmap(org, width, height);
else original = ImageProcessing.lumaToGreyscale(org, width, height);
}
Bitmap bitmap = null;
if (Preferences.SAVE_CHANGES) {
if (Preferences.USE_RGB) bitmap = ImageProcessing.rgbToBitmap(img, width, height);
else bitmap = ImageProcessing.lumaToGreyscale(img, width, height);
}
Log.i(TAG, "Saving.. previous=" + previous + " original=" + original + " bitmap=" + bitmap);
Looper.prepare();
new SavePhotoTask().execute(previous, original, bitmap);
} else {
Log.i(TAG, "Not taking picture because not enough time has passed since the creation of the Surface");
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
processing.set(false);
}
// Log.d(TAG, "END PROCESSING...");
processing.set(false);
}
};
private static final class SavePhotoTask extends AsyncTask<Bitmap, Integer, Integer> {
/**
* {@inheritDoc}
*/
@Override
protected Integer doInBackground(Bitmap... data) {
for (int i = 0; i < data.length; i++) {
Bitmap bitmap = data[i];
String name = String.valueOf(System.currentTimeMillis());
if (bitmap != null) save(name, bitmap);
}
return 1;
}
private void save(String name, Bitmap bitmap) {
File photo = new File(Environment.getExternalStorageDirectory(), name + ".jpg");
if (photo.exists()) photo.delete();
try {
FileOutputStream fos = new FileOutputStream(photo.getPath());
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
} catch (java.io.IOException e) {
Log.e("PictureDemo", "Exception in photoCallback", e);
}
}
}
}
AreaDetectorView.java
Code:
public class AreaDetectorView extends LinearLayout {
public static int Width;
public static int Height;
private static Paint BoxPaint = null;
private static Paint TextPaint = null;
private static Paint ArrowPaint = null;
private static Path mPath = null;
private static Rect mRect = null;
private static int lastX, lastY = 0;
private static boolean mBoxTouched = false;
private static boolean mArrowTouched = false;
private static Context mContext;
private static int ArrowWidth = 0;
private static Paint BoxPaint2 = null;
public AreaDetectorView(Context context) {
super(context);
mContext = context;
}
//attrs was not there
public AreaDetectorView(Context context, AttributeSet attrs) {
super(context,attrs);
mContext = context;
// TODO Auto-generated constructor stub
if (!this.getRootView().isInEditMode()) {
ArrowWidth =GetDisplayPixel(context, 30);
}
//InitDetectionArea();
InitMemberVariables();
setWillNotDraw(false);
}
public static int GetDisplayPixel(Context paramContext, int paramInt)
{
return (int)(paramInt * paramContext.getResources().getDisplayMetrics().density + 0.5F);
}
public static void InitMemberVariables() {
if (BoxPaint == null) {
BoxPaint = new Paint();
BoxPaint.setAntiAlias(true);
BoxPaint.setStrokeWidth(2.0f);
//BoxPaint.setStyle(Style.STROKE);
BoxPaint.setStyle(Style.FILL_AND_STROKE);
BoxPaint.setColor(ContextCompat.getColor(mContext, R.color.bwff_60));
}
if (ArrowPaint == null) {
ArrowPaint = new Paint();
ArrowPaint.setAntiAlias(true);
ArrowPaint.setColor(ContextCompat.getColor(mContext,R.color.redDD));
ArrowPaint.setStyle(Style.FILL_AND_STROKE);
}
if (TextPaint == null) {
TextPaint = new Paint();
TextPaint.setColor(ContextCompat.getColor(mContext,R.color.yellowL));
TextPaint.setTextSize(16);
//txtPaint.setTypeface(lcd);
TextPaint.setStyle(Style.FILL_AND_STROKE);
}
if (mPath == null) {
mPath = new Path();
} else {
mPath.reset();
}
if (mRect == null) {
mRect = new Rect();
}
if (BoxPaint2 == null) {
BoxPaint2 = new Paint();
BoxPaint2.setAntiAlias(true);
BoxPaint2.setStrokeWidth(2.0f);
//BoxPaint.setStyle(Style.STROKE);
BoxPaint2.setStyle(Style.STROKE);
BoxPaint2.setColor(ContextCompat.getColor(mContext,R.color.bwff_9e));
}
}
public static void InitDetectionArea() {
try {
int w = Prefe.DetectionArea.width();
int h = Prefe.DetectionArea.height();
int x = Prefe.DetectionArea.left;
int y = Prefe.DetectionArea.top;
// ver 2.6.0
if (Prefe.DetectionArea.left == 1
&& Prefe.DetectionArea.top == 1
&& Prefe.DetectionArea.right == 1
&& Prefe.DetectionArea.bottom == 1) {
w = Prefe.DisplayWidth / 4;
h = Prefe.DisplayHeight / 3;
// ver 2.5.9
w = Width / 4;
h = Height / 3;
Prefe.DetectorWidth = w; //UtilGeneralHelper.GetDisplayPixel(this, 100);
Prefe.DetectorHeight = h; //UtilGeneralHelper.GetDisplayPixel(this, 100);
x = (Prefe.DisplayWidth / 2) - (w / 2);
y = (Prefe.DisplayHeight / 2) - (h / 2);
// ver 2.5.9
x = (Width / 2) - (w / 2);
y = (Height / 2) - (h / 2);
}
//Prefe.DetectionArea = new Rect(x, x, x + Prefe.DetectorWidth, x + Prefe.DetectorHeight);
Prefe.DetectionArea = new Rect(x, y, x + w, y + h);
Prefe.gDetectionBitmapInt = new int[Prefe.DetectionArea.width() * Prefe.DetectionArea.height()];
Prefe.gDetectionBitmapIntPrev = new int[Prefe.DetectionArea.width() * Prefe.DetectionArea.height()];
} catch (Exception e) {
e.printStackTrace();
}
}
public static void SetDetectionArea(int x, int y, int w, int h) {
try {
Prefe.DetectionArea = new Rect(x, y, w, h);
} catch (Exception e) {
e.printStackTrace();
}
}
private void DrawAreaBox(Canvas canvas) {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
try {
if (this.getRootView().isInEditMode()) {
super.dispatchDraw(canvas);
return;
}
//canvas.save(Canvas.MATRIX_SAVE_FLAG);
//Prefe.DetectionAreaOrient = UtilGeneralHelper.GetDetectRectByOrientation();
canvas.drawColor(0);
mPath.reset();
canvas.drawRect(Prefe.DetectionArea, BoxPaint);
mPath.moveTo(Prefe.DetectionArea.right - ArrowWidth, Prefe.DetectionArea.bottom);
mPath.lineTo(Prefe.DetectionArea.right, Prefe.DetectionArea.bottom - ArrowWidth);
mPath.lineTo(Prefe.DetectionArea.right, Prefe.DetectionArea.bottom);
mPath.lineTo(Prefe.DetectionArea.right - ArrowWidth, Prefe.DetectionArea.bottom);
mPath.close();
canvas.drawPath(mPath, ArrowPaint);
mPath.reset();
//canvas.drawRect(Prefe.DetectionAreaOrient, BoxPaint2);
//canvas.drawRect(Prefe.DetectionAreaOrientPort, BoxPaint2);
TextPaint.setTextSize(16);
//TextPaint.setLetterSpacing(2);
TextPaint.setColor(ContextCompat.getColor(mContext,R.color.bwff));
TextPaint.getTextBounds(getResources().getString(R.string.str_detectarea), 0, 1, mRect);
canvas.drawText(getResources().getString(R.string.str_detectarea),
Prefe.DetectionArea.left + 4,
Prefe.DetectionArea.top + 4 + mRect.height(),
TextPaint);
int recH = mRect.height();
TextPaint.setStrokeWidth(1.2f);
TextPaint.setTextSize(18);
TextPaint.setColor(ContextCompat.getColor(mContext,R.color.redD_9e));
TextPaint.getTextBounds(getResources().getString(R.string.str_dragandmove), 0, 1, mRect);
canvas.drawText(getResources().getString(R.string.str_dragandmove),
Prefe.DetectionArea.left + 4,
Prefe.DetectionArea.top + 20 + mRect.height()*2,
TextPaint);
TextPaint.getTextBounds(getResources().getString(R.string.str_scalearea), 0, 1, mRect);
canvas.drawText(getResources().getString(R.string.str_scalearea),
Prefe.DetectionArea.left + 4,
Prefe.DetectionArea.top + 36 + mRect.height()*3,
TextPaint);
super.dispatchDraw(canvas);
//canvas.restore();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onDraw(Canvas canvas) {
try {
super.onDraw(canvas);
invalidate();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean retValue = true;
int X = (int)event.getX();
int Y = (int)event.getY();
//AppMain.txtLoc.setText(String.valueOf(X) + ", " + String.valueOf(Y));
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mBoxTouched = TouchedInBoxArea(X, Y);
//AppMain.txtLoc.setText("BoxTouched: " + String.valueOf(mBoxTouched));
if (!mBoxTouched) break;
lastX = X;
lastY = Y;
BoxPaint.setStyle(Style.FILL_AND_STROKE);
BoxPaint.setColor(ContextCompat.getColor(mContext,R.color.redD_9e));
mArrowTouched = TouchedInArrow(X, Y);
//AppMain.txtLoc.setText("ArrowTouched: " + String.valueOf(mBoxTouched));
if (mArrowTouched) {
ArrowPaint.setColor(ContextCompat.getColor(mContext,R.color.bwff_9e));
}
break;
case MotionEvent.ACTION_MOVE:
if (!mBoxTouched) break;
int moveX = X - lastX;
int moveY = Y - lastY;
//AppMain.txtLoc.setText("Move X, Y: " + String.valueOf(moveX) + "," + String.valueOf(moveY));
if (!mArrowTouched) {
if (Prefe.DetectionArea.left + moveX < 0) {
break;
}
// if (Prefe.DetectionArea.right + moveX > Prefe.gDisplay.getWidth()) {
// break;
// }
// ver 2.5.9
if (Prefe.DetectionArea.right + moveX > Width) {
break;
}
if (Prefe.DetectionArea.top + moveY < 0) {
break;
}
// if (Prefe.DetectionArea.bottom + moveY > Prefe.gDisplay.getHeight()) {
// break;
// }
// ver 2.5.9
if (Prefe.DetectionArea.bottom + moveY > Height) {
break;
}
}
if (mArrowTouched) {
if ((Prefe.DetectionArea.width() + moveX) < ArrowWidth * 2){
break;
}
if ((Prefe.DetectionArea.height() + moveY) < ArrowWidth * 2) {
break;
}
Prefe.DetectionArea.right += moveX;
Prefe.DetectionArea.bottom += moveY;
//Log.i("DBG", "W,H: " + String.valueOf(Prefe.DetectionArea.width()) + "," + String.valueOf(Prefe.DetectionArea.height()));
} else {
Prefe.DetectionArea.left += moveX;
Prefe.DetectionArea.right += moveX;
Prefe.DetectionArea.top += moveY;
Prefe.DetectionArea.bottom += moveY;
}
lastX = X;
lastY = Y;
//AppMain.txtLoc.setText(String.valueOf(Prefe.DetectionArea.left) + ", " + String.valueOf(Prefe.DetectionArea.top));
break;
case MotionEvent.ACTION_UP:
mBoxTouched = false;
mArrowTouched = false;
//BoxPaint.setStyle(Style.STROKE);
BoxPaint.setStyle(Style.FILL_AND_STROKE);
BoxPaint.setColor(ContextCompat.getColor(mContext,R.color.bwff_60));
ArrowPaint.setColor(ContextCompat.getColor(mContext,R.color.redDD));
//AppMain.txtLoc.setText(String.valueOf(Prefe.DetectionArea.left) + ", " + String.valueOf(Prefe.DetectionArea.top));
if (Prefe.DetectionArea.left < 0) {
Prefe.DetectionArea.left = 0;
}
// if (Prefe.DetectionArea.right > Prefe.gDisplay.getWidth()) {
// Prefe.DetectionArea.right = Prefe.gDisplay.getWidth();
// }
// ver 2.5.9
if (Prefe.DetectionArea.right > Width) {
Prefe.DetectionArea.right = Width;
}
if (Prefe.DetectionArea.top < 0) {
Prefe.DetectionArea.top = 0;
}
// if (Prefe.DetectionArea.bottom > Prefe.gDisplay.getHeight()) {
// Prefe.DetectionArea.bottom = Prefe.gDisplay.getHeight();
// }
if (Prefe.DetectionArea.bottom > Height) {
Prefe.DetectionArea.bottom = Height;
}
Prefe.gDetectionBitmapInt = new int[Prefe.DetectionArea.width() * Prefe.DetectionArea.height()];
Prefe.gDetectionBitmapIntPrev = new int[Prefe.DetectionArea.width() * Prefe.DetectionArea.height()];
//Prefe.gDetectionBitmapInt = null;
//Prefe.gDetectionBitmapIntPrev = null;
String area = String.valueOf(Prefe.DetectionArea.left)
+ "," + String.valueOf(Prefe.DetectionArea.top)
+ "," + String.valueOf(Prefe.DetectionArea.right)
+ "," + String.valueOf(Prefe.DetectionArea.bottom);
// UtilGeneralHelper.SavePreferenceSetting(Prefe.gContext, Prefe.PREF_DETECTION_AREA_KEY, area);
//Saving the value
SharedPrefsUtils.setStringPreference(mContext.getApplicationContext(), Prefe.PREF_DETECTION_AREA_KEY, area);
Log.v("TAG", SharedPrefsUtils.getStringPreference(mContext.getApplicationContext(),Prefe.PREF_DETECTION_AREA_KEY));
break;
}
invalidate();
return retValue;
}
private boolean TouchedInBoxArea(int x, int y) {
boolean retValue = false;
try {
if (x > Prefe.DetectionArea.left && x < Prefe.DetectionArea.right) {
if (y > Prefe.DetectionArea.top && y < Prefe.DetectionArea.bottom) {
retValue = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return retValue;
}
private boolean TouchedInArrow(int x, int y) {
boolean retValue = false;
try {
if (x > Prefe.DetectionArea.right - ArrowWidth && x < Prefe.DetectionArea.right) {
if (y > Prefe.DetectionArea.bottom - ArrowWidth && y < Prefe.DetectionArea.bottom) {
retValue = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return retValue;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
Width = width;
Height = height;
InitDetectionArea();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
for (int i = 0; i < this.getChildCount()-1; i++){
(this.getChildAt(i)).layout(l, t, r, b);
}
if (changed) {
// check width height
if (r != Width || b != Height) {
// size does not match
}
}
}
}
Prefe.java
Code:
public class Prefe extends Application{
...
public static final String PREF_DETECTION_AREA_KEY = "pref_detection_area_key";
}
static{
...
DetectionArea = new Rect(1, 1, 1, 1);
}
}

Categories

Resources