Java tutorial
/** * PhotoSorterActivity.java * * (c) Luke Hutchison (luke.hutch@mit.edu) * * -- * * Released under the MIT license (but please notify me if you use this code, so that I can give your project credit at * http://code.google.com/p/android-multitouch-controller ). * * MIT license: http://www.opensource.org/licenses/MIT * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ package com.karmick.dragcontroller; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.view.KeyEvent; public class PhotoSortrActivity extends AppCompatActivity { //PhotoSortrView photoSorter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setTitle(R.string.instructions); setContentView(R.layout.content_main); /* photoSorter = (PhotoSortrView) findViewById(R.id.sortsView); ArrayList<Drawable> IMAGES = new ArrayList<>(); IMAGES.add(getResources().getDrawable(R.drawable.catarina)); IMAGES.add(getResources().getDrawable(R.drawable.m74hubble)); IMAGES.add(getResources().getDrawable(R.drawable.sunset)); IMAGES.add(getResources().getDrawable(R.drawable.tahiti)); photoSorter.setIMAGES(IMAGES); */ changeFragmentFromActivity(new PhotoSortrFragment(), 0, 0, "PhotoSortrFragment"); } public void changeFragmentFromActivity(Fragment fragment, int a1, int a2, String tag) { String backStateName = fragment.getClass().getName(); FragmentManager manager = getSupportFragmentManager(); /*boolean fragmentPopped = manager.popBackStackImmediate (backStateName, 0); if (!fragmentPopped){ //fragment not in back stack, create it.*/ FragmentTransaction ft = manager.beginTransaction(); ft.replace(R.id.container, fragment); ft.addToBackStack(backStateName); ft.commit(); //} } @Override protected void onResume() { super.onResume(); //photoSorter.loadImages(this); } @Override protected void onPause() { super.onPause(); //photoSorter.unloadImages(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { //photoSorter.trackballClicked(); return true; } return super.onKeyDown(keyCode, event); } }