Skip to content

Instantly share code, notes, and snippets.

View code-twister's full-sized avatar

Mihaly Nagy code-twister

View GitHub Profile
/**
* Return the Fragment associated with a specified position.
*/
public abstract Fragment getItem(int position);
private static String makeFragmentName(int viewId, int index) {
return "android:switcher:" + viewId + ":" + index;
}
@Override
public Object instantiateItem(View container, int position) {
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
}
// Do we already have this fragment?
String name = makeFragmentName(container.getId(), position);
Fragment fragment = mFragmentManager.findFragmentByTag(name);
if (fragment != null) {
// Simple stack implementation, works as expected every time
private Stack<NavItem> navigationStack = new Stack<>();
// ...
// Navigating to a new screen/item in the stack
navigationStack.push(new NavItem(viewToBeAdded.getClass(), args));
// ...
public void useCaseExample() {
storageAbstraction.loadSomeData();
filterData();
doSomeComputation();
uiAbstraction.presentDataToUser();
}
@code-twister
code-twister / ComposableBuilder.java
Created November 17, 2017 10:51
Experiment trying to create a builder pattern which enforces certain params and others being optional, that's also inheritable.
public class Activity1$$IntentBuilder<NEXT> {
protected Map<String, String> params = new HashMap<>();
public Activity1FirstParam createActivity1() {
return new Activity1FirstParam();
}
protected class Activity1FirstParam {
public AfterExtra1 extra1(String extra1) {
@code-twister
code-twister / build.gradle
Created January 8, 2018 09:49
Gradle build file for Android Studio plugin
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url 'http://dl.bintray.com/jetbrains/intellij-plugin-service'
}
}
@code-twister
code-twister / plugin.xml
Created January 8, 2018 10:07
plugin xml for Android Studio
<idea-plugin>
<id>com.example.plugin</id>
<name>ExamplePlugin</name>
<vendor email="test@example.com" url="http://www.example.com">Example</vendor>
<description><![CDATA[
Some description of the plugin, what it does, so people can have a better idea if they want to use it
]]></description>
<change-notes><![CDATA[
@code-twister
code-twister / TestProjectComponent.java
Created January 8, 2018 10:34
Test project component for Android Studio plugin
package com.example.plugin;
import com.intellij.openapi.components.ProjectComponent;
import org.jetbrains.annotations.NotNull;
public class TestProjectComponent implements ProjectComponent {
private static final String TEST_PROJECT_COMPONENT_NAME = "TestProjectComponent";
@Override
@code-twister
code-twister / build.gradle
Created January 9, 2018 15:18
Gradle build file for Android Studio plugin with custom ide sandbox
...
intellij {
version '2017.1'
pluginName 'YOUR PLUGIN NAME HERE'
plugins 'android'
updateSinceUntilBuild false
alternativeIdePath "/Applications/Android Studio 3.0 Preview.app/Contents/"
}