Created
July 14, 2015 19:12
-
-
Save gon250/d09e56fa6dd3c004a0c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.samsung.android.sdk.gesture.Sgesture; | |
import com.samsung.android.sdk.gesture.SgestureHand; | |
import android.os.Looper; | |
public class GestureHand { | |
public static int UP = 1; | |
public static int DOWN = 2; | |
public static int LEFT = 3; | |
public static int RIGHT = 4; | |
private SgestureHand mGestureHand = null; | |
private SgestureHand.ChangeListener mChangeListener; | |
public GestureHand(Looper looper, Sgesture gesture) { | |
mGestureHand = new SgestureHand(looper, gesture); | |
} | |
public void setListener(SgestureHand.ChangeListener changeListener){ | |
mChangeListener = changeListener; | |
} | |
public boolean start(int mode){ | |
if(mChangeListener != null){ | |
mGestureHand.start(mode, mChangeListener); | |
return true; | |
} | |
return false; | |
} | |
public void stop(){ | |
mGestureHand.stop(); | |
} | |
public int getDirection(int angle){ | |
if(angle < 45 || angle >= 135){ | |
return DOWN; | |
} else if(angle >= 45 || angle < 135){ | |
return RIGHT; | |
} else if(angle >= 135 || angle < 225){ | |
return UP; | |
} else if(angle >= 225 || angle < 315){ | |
return LEFT; | |
} | |
return 0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wk.gon250.alrumbofestival; | |
import android.os.Bundle; | |
import android.support.v4.view.ViewPager; | |
import android.support.v7.app.ActionBarActivity; | |
import android.support.v7.widget.SearchView; | |
import android.support.v7.widget.Toolbar; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import com.samsung.android.sdk.SsdkUnsupportedException; | |
import com.samsung.android.sdk.gesture.Sgesture; | |
import com.samsung.android.sdk.gesture.SgestureHand; | |
import adapters.ViewPagerAdapter; | |
import customwidget.SlidingTabLayout; | |
import helpers.GestureHand; | |
public class MainActivity extends ActionBarActivity { | |
Toolbar toolbar; | |
ViewPager pager; | |
ViewPagerAdapter adapter; | |
SlidingTabLayout tabs; | |
CharSequence Titles[]={"16 Jul","17 Jul", "18 Jul"}; | |
int Numboftabs = 3; | |
SearchView searchView; | |
Sgesture mGesture; | |
GestureHand mGestureHand; | |
boolean isGesture = false; | |
SgestureHand.ChangeListener changeListener = new SgestureHand.ChangeListener() { | |
@Override | |
public void onChanged(SgestureHand.Info info) { | |
if(info.getType() == Sgesture.TYPE_HAND_PRIMITIVE){ | |
int direction = mGestureHand.getDirection(info.getAngle()); | |
switch (direction) { | |
case 3: | |
break; | |
case 4: | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
}; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
try{ | |
mGesture.initialize(this); | |
isGesture = mGesture.isFeatureEnabled(Sgesture.TYPE_HAND_PRIMITIVE); | |
mGestureHand = new GestureHand(getMainLooper(), mGesture); | |
mGestureHand.setListener(changeListener); | |
isGesture = mGestureHand.start(Sgesture.TYPE_HAND_PRIMITIVE); | |
} catch(IllegalArgumentException e){ | |
} catch (SsdkUnsupportedException e) { | |
} | |
// Creating The Toolbar and setting it as the Toolbar for the activity | |
toolbar = (Toolbar) findViewById(R.id.tool_bar); | |
setSupportActionBar(toolbar); | |
toolbar.setNavigationIcon(R.mipmap.ic_launcher); | |
// Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs. | |
adapter = new ViewPagerAdapter(getSupportFragmentManager(), Titles, Numboftabs); | |
// Assigning ViewPager View and setting the adapter | |
pager = (ViewPager) findViewById(R.id.pager); | |
pager.setAdapter(adapter); | |
// Assiging the Sliding Tab Layout View | |
tabs = (SlidingTabLayout) findViewById(R.id.tabs); | |
tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width | |
// Setting Custom Color for the Scroll bar indicator of the Tab View | |
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() { | |
@Override | |
public int getIndicatorColor(int position) { | |
return getResources().getColor(R.color.tabsScrollColor); | |
} | |
}); | |
// Setting the ViewPager For the SlidingTabsLayout | |
tabs.setViewPager(pager); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
// getMenuInflater().inflate(R.menu.menu_main, menu); | |
// searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); | |
// searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | |
// @Override | |
// public boolean onQueryTextSubmit(String query) { | |
// return false; | |
// } | |
// | |
// @Override | |
// public boolean onQueryTextChange(String newText) { | |
// | |
// Toast.makeText(MainActivity.this, newText, Toast.LENGTH_SHORT).show(); | |
// | |
// return false; | |
// } | |
// }); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch (item.getItemId()){ | |
case R.id.action_search: | |
break; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment