Last active
October 13, 2015 20:47
-
-
Save a-thomas/4253537 to your computer and use it in GitHub Desktop.
Formation Android 2)
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
public class InputStreamToString { | |
public static String convert(InputStream is) { | |
String line = ""; | |
StringBuilder builder = new StringBuilder(); | |
BufferedReader rd=new BufferedReader(new InputStreamReader(is)); | |
try { | |
while ((line = rd.readLine()) != null) { | |
builder.append(line); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return builder.toString(); | |
} | |
} |
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
public class ParlezVousPowerReceiver extends BroadcastReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
if (intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) { | |
// power connected | |
} else { | |
// power disconnected | |
} | |
} | |
} |
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
<receiver | |
android:name=".ParlezVousPowerReceiver" | |
android:enabled="true" > | |
<intent-filter> | |
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" /> | |
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" /> | |
</intent-filter> | |
</receiver> |
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
private ParlezVousPowerReceiver receiver; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
IntentFilter filter1 = new IntentFilter(Intent.ACTION_POWER_CONNECTED); | |
IntentFilter filter2 = new IntentFilter( | |
Intent.ACTION_POWER_DISCONNECTED); | |
receiver = new ParlezVousPowerReceiver(); | |
registerReceiver(receiver, filter1); | |
registerReceiver(receiver, filter2); | |
} | |
@Override | |
protected void onDestroy() { | |
super.onDestroy(); | |
unregisterReceiver(receiver); | |
} |
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
<com.excilys.parlezvous.ParlezVousView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@android:color/white" /> |
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
public class ParlezVousView extends SurfaceView { | |
Paint paint = new Paint(); | |
public ParlezVousView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
@Override | |
protected void onDraw(Canvas canvas) { | |
paint.setColor(Color.RED); | |
// Dessiner ici ! | |
} | |
@Override | |
public boolean onTouchEvent(MotionEvent event) { | |
// Gérer les actions ici ! | |
switch (event.getAction()) { | |
case MotionEvent.ACTION_UP: | |
// relâchement du doigt | |
break; | |
} | |
return true; | |
} | |
} |
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
@Override | |
public boolean onTouchEvent(MotionEvent event) { | |
switch (event.getAction()) { | |
case MotionEvent.ACTION_DOWN: | |
// Appui du doigt | |
break; | |
case MotionEvent.ACTION_UP: | |
// Relâchement du doigt | |
break; | |
case MotionEvent.ACTION_MOVE: | |
// Déplacement du doigt | |
break; | |
} | |
return true; | |
} |
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
private EditText usernameField; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
usernameField = (EditText) findViewById(R.id.username_field); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment